Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Start () {
- // Rigidbody2D
- body = GetComponent<Rigidbody2D> ();
- }
- void Update () {
- // Main Camera
- mainView = Camera.main;
- // Mouse Position
- var mousePosition = mainView.ScreenToWorldPoint (Input.mousePosition);
- Quaternion rotate = Quaternion.LookRotation (transform.position - mousePosition, Vector3.forward);
- // Rotation
- transform.rotation = rotate;
- transform.eulerAngles = new Vector3 (0, 0, transform.eulerAngles.z);
- // Reset Rigidbody2D
- body.velocity = Vector2.zero;
- body.angularVelocity = 0;
- // New Position
- var position = new Vector2 (transform.up.x, transform.up.y) * speed * Time.deltaTime;
- // Mouse Button Down
- if (Input.GetMouseButtonDown (0)) {
- pressed = true;
- }
- // Mouse Button Up
- if (Input.GetMouseButtonUp (0)) {
- pressed = false;
- }
- // Move Player
- if (pressed) {
- body.MovePosition (body.position + position);
- }
- }
Add Comment
Please, Sign In to add comment