OnTriggerEnter called but variable is never set

前端 未结 1 505
旧巷少年郎
旧巷少年郎 2021-01-22 01:05

I\'ve started learning Unity slowly using C# and it\'s been a blast thus far!

I\'ve run into a small problem (I hope it\'s a small problem) and gotten stuck, and have be

相关标签:
1条回答
  • 2021-01-22 01:47

    OnTriggerEnter requires a parameter (Collider other) or it won't match the signature Unity expects.

    private bool triggered = false;
    
        void OnTriggerEnter(Collider other) {
            Debug.Log("Triggered");
            this.triggered = true;
        }
    
        public bool Triggered {
    
            get { return this.triggered; }
        }
    }
    

    Also, as the documentation states:

    Note that trigger events are only sent if one of the colliders also has a rigid body attached.

    0 讨论(0)
提交回复
热议问题