Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class Controller : MonoBehaviour {
- public int speed = 1;
- void Update ()
- {
- float mouseX = Input.GetAxisRaw("Mouse X");
- if (mouseX != 0)
- {
- gameObject.GetComponent<Rigidbody>().isKinematic = false;
- if (mouseX < 0)
- {
- gameObject.GetComponent<Rigidbody>().AddForce(Vector3.left * speed, ForceMode.VelocityChange);
- }
- else
- {
- gameObject.GetComponent<Rigidbody>().AddForce(Vector3.right * speed, ForceMode.VelocityChange);
- }
- } else
- {
- gameObject.GetComponent<Rigidbody>().isKinematic = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment