Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class move : MonoBehaviour {
- public float speed = 20f;
- private Rigidbody2D rb;
- private int face = 1; //0 for up, 1 for right, 2 for down, 3 for left
- private float rt = 0f;
- void Start () {
- rb = GetComponent <Rigidbody2D> ();
- }
- void Update () {
- Vector3 cur = transform.position;
- if (Input.GetKey (KeyCode.A)) {
- cur.x += -speed * Time.deltaTime;
- }
- if (Input.GetKey (KeyCode.D)) {
- cur.x += speed * Time.deltaTime;
- }
- if (Input.GetKey (KeyCode.W)) {
- cur.y += speed * Time.deltaTime;
- }
- if (Input.GetKey (KeyCode.S)) {
- cur.y += -speed * Time.deltaTime;
- }
- transform.position = cur;
- rtt ();
- }
- void rtt () {
- float cur = Mathf.Atan2 (Input.mousePosition.y - Screen.height / 2f, Input.mousePosition.x - Screen.width / 2f) / Mathf.PI * 180f;
- transform.Rotate (0f, 0f, cur - rt); rt = cur;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement