Advertisement
renderbydavid

PlayerCntrl

Oct 21st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.10 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class PlayerCntrl : MonoBehaviour
  6. {
  7.     public Attacking Attk;
  8.     public Movement MyMovement;
  9.     bool Left, Right, Up, Down, GrabPos;
  10.     int FaceDir;
  11.     public int Tap;
  12.     public bool CanAttack, hasTap;
  13.     public Vector2 AttackPos, GrabbedPos;
  14.     private void Update()
  15.     {      
  16.         //if(Tap > 2)
  17.         //{
  18.         //    hasTap = true;
  19.         //    Tap = 0;
  20.         //}
  21.         //if(Input.GetKeyDown(KeyCode.A))
  22.         //{
  23.         //    if(Tap == 0)
  24.         //    {
  25.         //        Tap += 1;
  26.         //    }
  27.         //}
  28.         if (Input.GetKey(KeyCode.A) && !Up && !Down)
  29.         {
  30.             MyMovement.MoveLeft();
  31.             Left = true;
  32.             FaceDir = 1;
  33.             if (Mathf.Round(transform.position.x) == Mathf.Round(AttackPos.x))
  34.             {
  35.                 hasTap = false;
  36.                 CanAttack = true;
  37.                 if (!Attk.hasAttacked)
  38.                 {
  39.                     Attk.AttackLeft();
  40.                 }
  41.  
  42.             }
  43.             else
  44.             {
  45.                 CanAttack = false;
  46.                 Attk.isAttking = false;
  47.                 Attk.hasAttacked = false;
  48.                 GetComponent<Animator>().Play("PlayerWalkLeft");
  49.             }
  50.  
  51.         }
  52.         else
  53.         {
  54.             Left = false;
  55.         }
  56.         if (Input.GetKey(KeyCode.D) && !Up && !Down)
  57.         {
  58.             MyMovement.MoveRight();
  59.             Right = true;
  60.             FaceDir = 2;
  61.             if (Mathf.Round(transform.position.x) == Mathf.Round(AttackPos.x))
  62.             {
  63.                 CanAttack = true;
  64.                 Attk.AttackRight();
  65.             }
  66.             else
  67.             {
  68.                 CanAttack = false;
  69.                 Attk.isAttking = false;
  70.                 Attk.hasAttacked = false;
  71.                 GetComponent<Animator>().Play("PlayerWalkRight");
  72.             }
  73.         }
  74.         else
  75.         {
  76.             Right = false;
  77.         }
  78.         if (Input.GetKey(KeyCode.W) && !Left && !Right)
  79.         {
  80.             MyMovement.MoveUp();
  81.             Up = true;
  82.             FaceDir = 3;
  83.             if (Mathf.Round(transform.position.y) == Mathf.Round(AttackPos.y))
  84.             {
  85.                 CanAttack = true;
  86.                 Attk.AttackUp();
  87.             }
  88.             else
  89.             {
  90.                 CanAttack = false;
  91.                 Attk.isAttking = false;
  92.                 Attk.hasAttacked = false;
  93.                 GetComponent<Animator>().Play("PlayerWalkUp");
  94.             }
  95.         }
  96.         else
  97.         {
  98.             Up = false;
  99.         }
  100.         if (Input.GetKey(KeyCode.S) && !Left && !Right)
  101.         {
  102.             MyMovement.MoveDown();
  103.             Down = true;
  104.             FaceDir = 0;
  105.             if (Mathf.Round(transform.position.y) == Mathf.Round(AttackPos.y))
  106.             {
  107.                 CanAttack = true;
  108.                 Attk.AttackDown();
  109.             }
  110.             else
  111.             {
  112.                 CanAttack = false;
  113.                 Attk.isAttking = false;
  114.                 Attk.hasAttacked = false;
  115.                 GetComponent<Animator>().Play("PlayerWalkDown");
  116.             }
  117.         }
  118.         else
  119.         {
  120.             Down = false;
  121.         }
  122.         if(!Down && !Up && !Left && !Right)
  123.         {
  124.             Debug.Log("W");
  125.             Vector2 Round = new Vector2(Mathf.Round(transform.position.x), Mathf.Round(transform.position.y));
  126.             transform.position = Vector2.Lerp(transform.position, Round, 4 * Time.deltaTime);
  127.             AttackPos = new Vector2(Mathf.Round(transform.position.x), Mathf.Round(transform.position.y));
  128.             //Attk.isAttking = false;
  129.             Attk.hasAttacked = false;
  130.             if (!Attk.isAttking)
  131.             {
  132.                 GetComponent<Animator>().Play("PlayerIdle" + FaceDir);
  133.             }
  134.         }
  135.         else
  136.         {
  137.             transform.position = Vector2.Lerp(transform.position, MyMovement.Mover.position, 4 * Time.deltaTime);                
  138.         }
  139.     }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement