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 AttkShitBox : MonoBehaviour
- {
- public AICntrl AI;
- public Attacking Attk;
- public string CheckDirection;
- bool PlayerIsNextToMe;
- private void OnTriggerEnter2D(Collider2D collision)
- {
- if(collision.tag == "Player")
- {
- AI.isMoving = false;
- AI.AIAttking = true;
- PlayerIsNextToMe = true;
- StartCoroutine("DoAttk");
- }
- }
- public IEnumerator DoAttk()
- {
- while (true)
- {
- yield return new WaitForSeconds(1f);
- if(!PlayerIsNextToMe)
- {
- AI.AIAttking = false;
- AI.isMoving = true;
- yield break;
- }
- else
- {
- Invoke(CheckDirection, 0);
- }
- }
- }
- void CheckDown()
- {
- RaycastHit2D down = Physics2D.Raycast(AI.transform.position, Vector2.down, 1.3f, 1 << 0);
- if (!down)
- {
- PlayerIsNextToMe = false;
- }
- else
- {
- if(down.transform.tag == "Player")
- {
- Attk.AttackDown();
- }
- else
- {
- PlayerIsNextToMe = false;
- }
- }
- }
- void CheckUp()
- {
- RaycastHit2D up = Physics2D.Raycast(AI.transform.position, Vector2.up, 1.3f, 1 << 0);
- if (!up)
- {
- PlayerIsNextToMe = false;
- }
- else
- {
- if (up.transform.tag == "Player")
- {
- Attk.AttackUp();
- }
- else
- {
- PlayerIsNextToMe = false;
- }
- }
- }
- void CheckLeft()
- {
- RaycastHit2D left = Physics2D.Raycast(AI.transform.position, Vector2.left, 1.3f, 1 << 0);
- if (!left)
- {
- PlayerIsNextToMe = false;
- }
- else
- {
- if (left.transform.tag == "Player")
- {
- Attk.AttackLeft();
- }
- else
- {
- PlayerIsNextToMe = false;
- }
- }
- }
- void CheckRight()
- {
- RaycastHit2D Right = Physics2D.Raycast(AI.transform.position, Vector2.right, 1.3f, 1 << 0);
- if (!Right)
- {
- PlayerIsNextToMe = false;
- }
- else
- {
- if (Right.transform.tag == "Player")
- {
- Attk.AttackRight();
- }
- else
- {
- PlayerIsNextToMe = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment