TeHArGiS10

Untitled

Feb 15th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Controller : MonoBehaviour {
  4.  
  5. public int speed = 1;
  6.  
  7. void Update ()
  8. {
  9. float mouseX = Input.GetAxisRaw("Mouse X");
  10.  
  11. if (mouseX != 0)
  12. {
  13. gameObject.GetComponent<Rigidbody>().isKinematic = false;
  14.  
  15. if (mouseX < 0)
  16. {
  17. gameObject.GetComponent<Rigidbody>().AddForce(Vector3.left * speed, ForceMode.VelocityChange);
  18. }
  19. else
  20. {
  21. gameObject.GetComponent<Rigidbody>().AddForce(Vector3.right * speed, ForceMode.VelocityChange);
  22. }
  23. } else
  24. {
  25. gameObject.GetComponent<Rigidbody>().isKinematic = true;
  26. }
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment