我想要做的是當我的角色(ThirdPerSonController)碰到一個立方體時檢測每一面。事實上,我的主要目標是檢測我的玩家何時站在頂部的立方體表面上。這是我的腳本:有沒有辦法使用Vector3開關/外殼?
switch (side)
嚴重性代碼說明項目文件的線路抑制狀態 錯誤CS0151 A開關表達式或case標籤必須是:
using UnityEngine; using System.Collections; public class Test : MonoBehaviour { void OnCollisionEnter(Collision collision) { ContactPoint contact = collision.contacts[0]; Vector3 normal = contact.normal; Vector3 inverseNormal = transform.InverseTransformDirection(normal); Vector3 roundNormal = RoundVector3(inverseNormal); ReturnSide(roundNormal); } Vector3 RoundVector3(Vector3 convertThis) { int x = (int)Mathf.Round(convertThis.x); int y = (int)Mathf.Round(convertThis.y); int z = (int)Mathf.Round(convertThis.z); Vector3 returnVector = new Vector3(x, y, z); return returnVector; } void ReturnSide(Vector3 side) { string output = null; switch (side) { case Vector3.down: output = "Down"; break; case Vector3.up: output = "Up"; break; case Vector3.back: output = "Back"; break; case Vector3.forward: output = "Front"; break; case Vector3.left: output = "Left"; break; case Vector3.right: output = "Right"; break; } Debug.Log(output + " was hit."); } // Use this for initialization void Start() { } // Update is called once per frame void Update() { } }
我就行收到錯誤bool,char,string,integral,enum或者相應的可以爲null的類型test.cs 33 Active
簡單的答案是否定的,忘記這一點。你做這件事的方式很簡單**有一個觸發器或對撞機,在每一個面上**。這是製作視頻遊戲的絕對基礎。請享用。 – Fattie