Version: 2021.1

描述

当用户在 Collider 上按下鼠标按钮时,将调用 OnMouseDown

This event is sent to all scripts of the GameObject with Collider. Scripts of the parent or child objects do not receive this event.

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class ExampleClass : MonoBehaviour { void OnMouseDown() { // Destroy the gameObject after clicking on it Destroy(gameObject); } }

在属于 Ignore Raycast 层的对象上,不调用该函数。

当且仅当 Physics.queriesHitTriggers 为 true 时,才在标记为触发器的碰撞体上调用该函数。

OnMouseDown 可以是协程。