OnMouseDown

確認済のバージョン: 4

-

難易度: 初級

コライダーや GUI 要素上のマウスクリックを検知する方法を学びます。

OnMouseDown

初級 Scripting

MouseClick

Code snippet

using UnityEngine;
using System.Collections;

public class MouseClick : MonoBehaviour
{
    void OnMouseDown ()
    {
        rigidbody.AddForce(-transform.forward * 500f);
        rigidbody.useGravity = true;
    }
}
#pragma strict

function OnMouseDown ()
{
    rigidbody.AddForce(-transform.forward * 500f);
    rigidbody.useGravity = true;
}
import UnityEngine
import System.Collections


public class ClickColourChange(MonoBehaviour):

    private def OnMouseDown():
        rigidbody.AddForce(-transform.forward * 500f);
        rigidbody.useGravity = true;