Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MoveHero : MonoBehaviour {
  5. private RaycastHit hit;
  6. public CharacterController controler;
  7.  
  8. public float gravity = 20.0f;
  9. private float speed = 7.0f;
  10. private float maxDistance = 1000;
  11. private Vector3 ourPos;
  12.  
  13. // Use this for initialization
  14. void Start(){
  15. ourPos=controler.transform.position;
  16. if(animation["idle"]){ animation["idle"].layer = 1; }
  17.  
  18. }
  19.  
  20. // Update is called once per frame
  21. void Update(){
  22. moveHero();
  23. if(Input.GetMouseButtonDown(1)) {
  24. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  25.  
  26. if(Physics.Raycast(ray,out hit)){
  27. ourPos=hit.point;
  28. }
  29. }
  30.  
  31.  
  32. }
  33.  
  34. void moveHero(){
  35.  
  36. if(Vector3.Distance(ourPos,controler.transform.position)<maxDistance && ourPos != controler.transform.position){
  37.  
  38. controler.SimpleMove((ourPos-controler.transform.position).normalized * speed );
  39. controler.transform.LookAt(new Vector3(ourPos.x,controler.transform.position.y,ourPos.z));
  40. if(Vector3.Distance(ourPos,controler.transform.position)>5){
  41. print("WALK");
  42. controler.gameObject.animation.CrossFade ("walk");
  43. }
  44. else{
  45. print("IDLE");
  46. controler.gameObject.animation.CrossFade ("idle",1.5f);
  47. }
  48.  
  49. }
  50. else{
  51.  
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement