
OnMouseDown
Tutorial
Beginner
+10XP
5 mins
(34)
Unity Technologies

콜라이더 또는 GUI 요소에 대한 마우스 클릭을 감지하는 방법을 알아봅니다.
이 튜토리얼은 스크립팅의 기초 프로젝트에 포함되어 있습니다.
이전: GetAxis
다음: GetComponent
1. OnMouseDown
MouseClick
using UnityEngine;
using System.Collections;
public class MouseClick : MonoBehaviour
{
private Rigidbody rb;
private void Awake()
{
rb = GetComponent<Rigidbody>();
}
void OnMouseDown ()
{
rb.AddForce(-transform.forward * 500f);
rb.useGravity = true;
}
}