반응형
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 );
}
}
}
반응형
'Programing > unity' 카테고리의 다른 글
유니티,unity, 하늘에서 떨어지는 것 받기 게임,똥피하기 게임 (0) | 2017.02.27 |
---|---|
유니티,unity,다른오브젝트의 위치에 따라서 방향바꾸기 (0) | 2017.02.26 |
유니티,unity,Raycast를 통해 앞쪽의 오브젝트 파악하기,DrawRay,RaycastHit (0) | 2017.02.26 |
unity,유니티 ,마우스 이동 상하,방향으로 캐릭터 회전 (0) | 2017.02.25 |
unity,유니티 ,마우스 이동 좌우,방향으로 캐릭터 회전 (1) | 2017.02.25 |