Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class MoveHero : MonoBehaviour {
- private RaycastHit hit;
- public CharacterController controler;
- public float gravity = 20.0f;
- private float speed = 7.0f;
- private float maxDistance = 1000;
- private Vector3 ourPos;
- // Use this for initialization
- void Start(){
- ourPos=controler.transform.position;
- if(animation["idle"]){ animation["idle"].layer = 1; }
- }
- // Update is called once per frame
- void Update(){
- moveHero();
- if(Input.GetMouseButtonDown(1)) {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if(Physics.Raycast(ray,out hit)){
- ourPos=hit.point;
- }
- }
- }
- void moveHero(){
- if(Vector3.Distance(ourPos,controler.transform.position)<maxDistance && ourPos != controler.transform.position){
- controler.SimpleMove((ourPos-controler.transform.position).normalized * speed );
- controler.transform.LookAt(new Vector3(ourPos.x,controler.transform.position.y,ourPos.z));
- if(Vector3.Distance(ourPos,controler.transform.position)>5){
- print("WALK");
- controler.gameObject.animation.CrossFade ("walk");
- }
- else{
- print("IDLE");
- controler.gameObject.animation.CrossFade ("idle",1.5f);
- }
- }
- else{
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement