Version: 2020.3

描述

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

此事件将发送到具有 Collider 或 GUIElement 的 GameObject 的所有脚本。父对象或子对象的脚本不会收到此事件。

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 可以是协程。