본문 바로가기
Programing/unity

unity,유니티,Raycast 여러오브젝트 검사,DrawRay,RaycastAll,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[] hits;

hits=Physics.RaycastAll(transform.position , transform.forward, 8.0f);

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

for (int i = 0; i < hits.Length; i++) {

RaycastHit hit = hits [i];

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

}


}

}



반응형