본문 바로가기
Programing/unity

유니티,unity,Raycast를 통해 앞쪽의 오브젝트 파악하기,DrawRay,RaycastHit

by 고니피즈 2017. 2. 26.
반응형

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class CsRaycast : MonoBehaviour {


private float speed = 5.0f;

// Update is called once per frame

void Update () {

float amtMove = speed * Time.deltaTime;

float hor = Input.GetAxis ("Horizontal");

transform.Translate (Vector3 . right * hor*amtMove);


Debug.DrawRay (transform.position,transform.forward*8,Color.red);

//  레이캐스트가 빨간줄로 실제로 보게 만들어 준다.

RaycastHit hit;

if(Physics.Raycast(transform.position , transform.forward, out hit , 8))

// (시작점,방향 ,hit info,거리)

{

Debug.Log ( hit.collider.gameObject.name );

// 광선이 충돌한 오브젝트를 로그창에 보여 준다.

}

}

}


반응형