void OnTriggerEnter(Collider other) { Destroy(other.gameObject); } } OnTriggerEnter每当触发对撞机碰到另一个对撞机时都会发送一条消息。在这种情况下,我们要告诉它销毁一切。保存脚本并返回到Unity编辑器。将多维数据集从层次结构拖动到“项目”面板。您会注意到层次结构中的多维数据集文本已变为蓝色。这是因为我们...
publicclassExplosion:MonoBehaviour{[SerializeField]intexplosionDamage=50;privatevoidOnTriggerEnter(Collider other){if(other.gameObject.TryGetComponent(outIDamageable damageableObject)){damageableObject.Damage(explosionDamage);}}} Copy Passing information to an interface In this example, damageable classes accept a...
如果你没有给墙壁添加Collider,那么你就能穿过一堵墙。当然在Unity中,当你Create一个3D Object的时候,那个...选Is Trigger选项。勾选了Trigger选项之后,其他的Collider就不会和它碰撞,而可以进入这个Collider,并触发OnTriggerEnter()等函数,于是我们可以在
To use IntelliSense for Unity messages:Place the cursor on a new line inside the body of a class that derives from MonoBehaviour. Begin typing the name of a Unity message, such as OnTriggerEnter. Once the letters "ontri" have been typed, a list of IntelliSense suggestions appears....
To use IntelliSense for Unity messages:Place the cursor on a new line inside the body of a class that derives from MonoBehaviour. Begin typing the name of a Unity message, such as OnTriggerEnter. Once the letters "ontri" have been typed, a list of IntelliSense suggestions appears....
To use IntelliSense for Unity messages:Place the cursor on a new line inside the body of a class that derives from MonoBehaviour. Begin typing the name of a Unity message, such as OnTriggerEnter. Once the letters "ontri" have been typed, a list of IntelliSense suggestions appears....
Log(x)).AddTo(disposables); } void OnTriggerEnter(Collider other) { // .Clear() => all inner disposable called Dispose and list is cleared. // .Dispose() => all inner disposable called Dispose and after Add, called Dispose immediately. disposables.Clear(); }...
OnTriggerEnter OnTriggerEnter is called when the Collider other enters the trigger. OnTriggerEnter2D Sent when another object enters a trigger collider attached to this object (2D physics only). OnTriggerExit OnTriggerExit is called when the Collider other has stopped touching the trigger. OnTriggerExi...
Learn how to create video games using Unity, the world-leading free-to-use game development tool. We start super simple so you need no prior experience of Unity or coding! With our online tutorials, you'll be amazed what you can achieve right from the first moment you start the course....
void OnTriggerEnter2D(Collider2D collider) { // If the player hits the trigger. if (collider.gameObject.tag == "Player") { // More on game controller shortly. GameController.Score++; // You don’t do: Destroy(this); because 'this' // is a script component on a game object so you...