Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class PlayerCntrl : MonoBehaviour
- {
- public Attacking Attk;
- public Movement MyMovement;
- bool Left, Right, Up, Down, GrabPos;
- int FaceDir;
- public int Tap;
- public bool CanAttack, hasTap;
- public Vector2 AttackPos, GrabbedPos;
- private void Update()
- {
- //if(Tap > 2)
- //{
- // hasTap = true;
- // Tap = 0;
- //}
- //if(Input.GetKeyDown(KeyCode.A))
- //{
- // if(Tap == 0)
- // {
- // Tap += 1;
- // }
- //}
- if (Input.GetKey(KeyCode.A) && !Up && !Down)
- {
- MyMovement.MoveLeft();
- Left = true;
- FaceDir = 1;
- if (Mathf.Round(transform.position.x) == Mathf.Round(AttackPos.x))
- {
- hasTap = false;
- CanAttack = true;
- if (!Attk.hasAttacked)
- {
- Attk.AttackLeft();
- }
- }
- else
- {
- CanAttack = false;
- Attk.isAttking = false;
- Attk.hasAttacked = false;
- GetComponent<Animator>().Play("PlayerWalkLeft");
- }
- }
- else
- {
- Left = false;
- }
- if (Input.GetKey(KeyCode.D) && !Up && !Down)
- {
- MyMovement.MoveRight();
- Right = true;
- FaceDir = 2;
- if (Mathf.Round(transform.position.x) == Mathf.Round(AttackPos.x))
- {
- CanAttack = true;
- Attk.AttackRight();
- }
- else
- {
- CanAttack = false;
- Attk.isAttking = false;
- Attk.hasAttacked = false;
- GetComponent<Animator>().Play("PlayerWalkRight");
- }
- }
- else
- {
- Right = false;
- }
- if (Input.GetKey(KeyCode.W) && !Left && !Right)
- {
- MyMovement.MoveUp();
- Up = true;
- FaceDir = 3;
- if (Mathf.Round(transform.position.y) == Mathf.Round(AttackPos.y))
- {
- CanAttack = true;
- Attk.AttackUp();
- }
- else
- {
- CanAttack = false;
- Attk.isAttking = false;
- Attk.hasAttacked = false;
- GetComponent<Animator>().Play("PlayerWalkUp");
- }
- }
- else
- {
- Up = false;
- }
- if (Input.GetKey(KeyCode.S) && !Left && !Right)
- {
- MyMovement.MoveDown();
- Down = true;
- FaceDir = 0;
- if (Mathf.Round(transform.position.y) == Mathf.Round(AttackPos.y))
- {
- CanAttack = true;
- Attk.AttackDown();
- }
- else
- {
- CanAttack = false;
- Attk.isAttking = false;
- Attk.hasAttacked = false;
- GetComponent<Animator>().Play("PlayerWalkDown");
- }
- }
- else
- {
- Down = false;
- }
- if(!Down && !Up && !Left && !Right)
- {
- Debug.Log("W");
- Vector2 Round = new Vector2(Mathf.Round(transform.position.x), Mathf.Round(transform.position.y));
- transform.position = Vector2.Lerp(transform.position, Round, 4 * Time.deltaTime);
- AttackPos = new Vector2(Mathf.Round(transform.position.x), Mathf.Round(transform.position.y));
- //Attk.isAttking = false;
- Attk.hasAttacked = false;
- if (!Attk.isAttking)
- {
- GetComponent<Animator>().Play("PlayerIdle" + FaceDir);
- }
- }
- else
- {
- transform.position = Vector2.Lerp(transform.position, MyMovement.Mover.position, 4 * Time.deltaTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement