본문 바로가기

Programming

Move , Turn

Move.cs
------------------------------------------------------------------------------------
using UnityEngine;

using System.Collections;


public class move : MonoBehaviour {

RaycastHit Hit;

Vector3 Click;

float MoveSpeed = 5f;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

if (Input.GetMouseButton (0)) {

Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out Hit);

Click = Hit.point;

transform.Translate ((Click - transform.position).normalized * MoveSpeed * Time.deltaTime);

}


}

}








Turn.cs
------------------------------------------------------------------------------------

using UnityEngine;

using System.Collections;


public class Turn : MonoBehaviour {

RaycastHit Hit;

float TurnSpeed;

Vector3 Click;

Quaternion dir;

// Use this for initialization

void Start () {

TurnSpeed = 5f;

}

// Update is called once per frame

void Update () {

if ( Input.GetMouseButton(0)) {

Physics.Raycast( Camera.main.ScreenPointToRay( Input.mousePosition), out Hit );

Click = Hit.point;

dir = Quaternion.LookRotation((Click - transform.position).normalized);

dir.x = 0;

dir.z = 0;

transform.rotation = Quaternion.Slerp(transform.rotation, dir, TurnSpeed * Time.deltaTime);                                   

}

}

}



'Programming' 카테고리의 다른 글

SQL 문법 정리 - SELECT  (0) 2015.02.03
관계 데이터 모델  (0) 2015.01.31
C# 스크립트  (0) 2015.01.29
Unity 기본 인터페이스  (0) 2015.01.29
Unity 동영상 강좌 링크  (0) 2015.01.29