ankittanwar

PlayerControl

Jul 31st, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. /*
  2.     This Script uses Pixelplacement Plugin from Unity Asset Store.
  3.     If you face any problem reach out to me.
  4. */
  5.  
  6. using UnityEngine;
  7. using System.Collections.Generic;
  8.  
  9. public class PlayerControl : MonoBehaviour
  10. {
  11.    
  12.     #region Readonly
  13.     public readonly static Vector2
  14.         Up = new Vector2(0, 1),
  15.         Down = new Vector2(0, -1),
  16.         Left = new Vector2(-1, 0),
  17.         Right = new Vector2(1, 0);
  18.     #endregion
  19.  
  20.     private void Update()
  21.     {
  22.         if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) Move(Right);
  23.         if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) Move(Left);
  24.         if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)) Move(Up);
  25.         if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) Move(Down);
  26.     }
  27.  
  28.     void Move(Vector2 d)
  29.     {
  30.         d *= 0.5f;
  31.         Vector2 dir;
  32.  
  33.         dir.x = d.x - d.y;
  34.         dir.y = (d.x + d.y) / 2;
  35.        
  36.         Pixelplacement.Tween.Position(transform, (transform.position + (Vector3)dir), 0.25f , 0);
  37.     }
  38. }
Add Comment
Please, Sign In to add comment