Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. public class MoveOnAxisInput : MonoBehaviour
  2. {
  3.         public string horizaontalAxis = "Horizontal";
  4.         public string verticalAxis = "Vertical";
  5.         public float speed = 1.0f;
  6.  
  7.         Vector3 lookPos;
  8.    
  9.     // Update is called once per frame
  10.     void Update ()
  11.    
  12.     {
  13.         Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  14.  
  15.         RaycastHit hit;
  16.  
  17.         if (Physics.Raycast (ray, out hit, 100))
  18.         {
  19.             lookPos = hit.point;
  20.             //audio.Play;
  21.         }
  22.  
  23.         Vector3 lookDir = lookPos - transform.position;
  24.         lookDir.y = 0;
  25.  
  26.         transform.LookAt (transform.position + lookDir, Vector3.up);
  27.  
  28.             transform.position += (Vector3.right*Input.GetAxis(horizaontalAxis) + Vector3.forward*Input.GetAxis(verticalAxis)).normalized*speed*Time.deltaTime;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement