0
我試圖修改碰撞後的類組件屬性, 但該屬性似乎沒有設置。Unity在碰撞後修改組件屬性
void OnCollisionExit2D (Collision2D myCollision) {
Debug.Log ("OnCollisionExit2D in Player:" + myCollision);
CompoMyClass compo = myCollision.gameObject.GetComponent<CompoMyClass>();
if (compo.collideOnce == true)
return;
compo.collideOnce = true;
// it always goes here :(
}
你知道爲什麼嗎?
public class CompoMyClass : MonoBehaviour {
public bool collideOnce = false;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
}
}
你能從CompMyClass發佈代碼嗎? collideOnce的類型很重要,以及如何訪問屬性 – David
這就好像我擁有的gameObject是一個副本,而不是原來的副本? – user3692403