Advertisement
Guest User

asd

a guest
Mar 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class move : MonoBehaviour {
  6.  
  7.     public float speed = 20f;
  8.     private Rigidbody2D rb;
  9.     private int face = 1; //0 for up, 1 for right, 2 for down, 3 for left
  10.     private float rt = 0f;
  11.  
  12.     void Start () {
  13.         rb = GetComponent <Rigidbody2D> ();
  14.     }
  15.    
  16.     void Update () {
  17.         Vector3 cur = transform.position;
  18.         if (Input.GetKey (KeyCode.A)) {
  19.             cur.x += -speed * Time.deltaTime;
  20.         }
  21.         if (Input.GetKey (KeyCode.D)) {
  22.             cur.x += speed * Time.deltaTime;
  23.         }
  24.         if (Input.GetKey (KeyCode.W)) {
  25.             cur.y += speed * Time.deltaTime;
  26.         }
  27.         if (Input.GetKey (KeyCode.S)) {
  28.             cur.y += -speed * Time.deltaTime;
  29.         }
  30.         transform.position = cur;
  31.         rtt ();
  32.     }
  33.  
  34.     void rtt () {
  35.         float cur = Mathf.Atan2 (Input.mousePosition.y - Screen.height / 2f, Input.mousePosition.x - Screen.width / 2f) / Mathf.PI * 180f;
  36.         transform.Rotate (0f, 0f, cur - rt); rt = cur;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement