반응형
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 );
// 광선이 충돌한 오브젝트를 로그창에 보여 준다.
}
}
}
반응형
'Programing > unity' 카테고리의 다른 글
유니티,unity,다른오브젝트의 위치에 따라서 방향바꾸기 (0) | 2017.02.26 |
---|---|
unity,유니티,Raycast 여러오브젝트 검사,DrawRay,RaycastAll,RaycastHit (0) | 2017.02.26 |
unity,유니티 ,마우스 이동 상하,방향으로 캐릭터 회전 (0) | 2017.02.25 |
unity,유니티 ,마우스 이동 좌우,방향으로 캐릭터 회전 (1) | 2017.02.25 |
유니티,unity, CharacterController 를 이용한 캐릭터이동 (0) | 2017.02.25 |