renderbydavid

AttkShitBox

Oct 22nd, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class AttkShitBox : MonoBehaviour
  6. {
  7.     public AICntrl AI;
  8.     public Attacking Attk;
  9.     public string CheckDirection;
  10.     bool PlayerIsNextToMe;
  11.     private void OnTriggerEnter2D(Collider2D collision)
  12.     {
  13.         if(collision.tag == "Player")
  14.         {
  15.             AI.isMoving = false;
  16.             AI.AIAttking = true;
  17.             PlayerIsNextToMe = true;
  18.             StartCoroutine("DoAttk");
  19.         }
  20.     }
  21.  
  22.     public IEnumerator DoAttk()
  23.     {
  24.         while (true)
  25.         {
  26.             yield return new WaitForSeconds(1f);
  27.             if(!PlayerIsNextToMe)
  28.             {
  29.                 AI.AIAttking = false;
  30.                 AI.isMoving = true;
  31.                 yield break;
  32.             }
  33.             else
  34.             {
  35.                 Invoke(CheckDirection, 0);
  36.             }
  37.            
  38.            
  39.         }
  40.     }
  41.  
  42.     void CheckDown()
  43.     {
  44.         RaycastHit2D down = Physics2D.Raycast(AI.transform.position, Vector2.down, 1.3f, 1 << 0);
  45.         if (!down)
  46.         {
  47.             PlayerIsNextToMe = false;
  48.         }
  49.         else
  50.         {
  51.             if(down.transform.tag == "Player")
  52.             {
  53.                 Attk.AttackDown();
  54.             }
  55.             else
  56.             {
  57.                 PlayerIsNextToMe = false;
  58.             }
  59.  
  60.         }
  61.     }
  62.  
  63.     void CheckUp()
  64.     {
  65.         RaycastHit2D up = Physics2D.Raycast(AI.transform.position, Vector2.up, 1.3f, 1 << 0);
  66.         if (!up)
  67.         {
  68.             PlayerIsNextToMe = false;
  69.         }
  70.         else
  71.         {
  72.             if (up.transform.tag == "Player")
  73.             {
  74.                 Attk.AttackUp();
  75.             }
  76.             else
  77.             {
  78.                 PlayerIsNextToMe = false;
  79.             }
  80.         }
  81.     }
  82.  
  83.     void CheckLeft()
  84.     {
  85.         RaycastHit2D left = Physics2D.Raycast(AI.transform.position, Vector2.left, 1.3f, 1 << 0);
  86.         if (!left)
  87.         {
  88.             PlayerIsNextToMe = false;
  89.         }
  90.         else
  91.         {
  92.             if (left.transform.tag == "Player")
  93.             {
  94.                 Attk.AttackLeft();
  95.             }
  96.             else
  97.             {
  98.                 PlayerIsNextToMe = false;
  99.             }
  100.         }
  101.     }
  102.  
  103.     void CheckRight()
  104.     {
  105.         RaycastHit2D Right = Physics2D.Raycast(AI.transform.position, Vector2.right, 1.3f, 1 << 0);
  106.         if (!Right)
  107.         {
  108.             PlayerIsNextToMe = false;
  109.         }
  110.         else
  111.         {
  112.             if (Right.transform.tag == "Player")
  113.             {
  114.                 Attk.AttackRight();
  115.             }
  116.             else
  117.             {
  118.                 PlayerIsNextToMe = false;
  119.             }
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment