我试图在碰撞后修改类组件的属性,但似乎没有设置该属性。
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 () {
}
}