Version: 2022.2

描述

当用户单击 Collider 并仍然按住鼠标时,将调用 OnMouseDrag。

在按住鼠标按钮的情况下,每帧调用一次 OnMouseDrag。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Renderer rend;

void Start() { rend = GetComponent<Renderer>(); }

void OnMouseDrag() { rend.material.color -= Color.white * Time.deltaTime; } }

Note: This function is not called on objects that belong to Ignore Raycast layer.

This function is called on Colliders and 2D Colliders marked as trigger when the following properties are set to true:

- For 3D physics: Physics.queriesHitTriggers

- For 2D physics: Physics2D.queriesHitTriggers

OnMouseDrag 可以是协程,在函数中只是使用 yield 语句。 此事件将发送至附加到 Collider 的所有脚本。