[Unity}RayCast

언어/Unity 2018. 1. 31. 15:29
728x90

Raycast


raycast를 통해 직선상에 있는 오브젝트 물체의 정보와 위치를 알수있다.


Physics.Raycas(v1, v2, out hit, distacne);


첫번째 매개변수는 시작하는 곳.

두번쨰 매개변수는 방향을나타냄.

세번째 매개변수는 RacastHit

네번째 매개변수는 거리를 나타냄.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using UnityEngine;
using System.Collections;
 
public class ray : MonoBehaviour {
 
    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
        if (Input.GetKey(KeyCode.A))
        {
            RaycastHit hit;
            if(Physics.Raycast(Vector3.zero, Vector3.up,out hit, 100f)) {
                Debug.Log(hit.collider.gameObject.name);
            }
        }
    }
}
 
cs


'언어 > Unity' 카테고리의 다른 글

[Unity] 좌표로 Mesh만들기  (0) 2018.02.06
[Unity]마우스클릭으로 Collider만들기  (0) 2018.02.05
[Unity] GUI 만들기  (0) 2018.01.29
[Unity}Nullable  (0) 2018.01.25
[Unity]List사용  (0) 2018.01.24