Advertisement
Salasander

Player Check

May 24th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerCheck : MonoBehaviour
  6. {
  7.     /// <summary>
  8.     /// MAKE SURE THE COLLIDER ATTACHED TO THIS SCRIPT IS A TRIGGER AND 2D
  9.     /// ALSO MAKE SURE THE PLAYER IS TAGGED AS PLAYER
  10.     /// ALSO MAKE SURE THE FILE NAME IN THE PROJECT IS THE SAME AS THE CLASS NAME P.S. That's "PlayerCheck"
  11.     /// </summary>
  12.  
  13.     private void OnTriggerEnter2D(Collider2D collision)
  14.     {
  15.         if(collision.gameObject.tag == "Player")
  16.         {                                   //     V     Change this name to whatever you called the project file for the melee enemy AI
  17.             collision.gameObject.GetComponent<MeleeEnemyAI>().playerInRange = true;
  18.         }
  19.     }
  20.  
  21.     private void OnTriggerExit2D(Collider2D collision)
  22.     {
  23.         if(collision.gameObject.tag == "Player")
  24.         {                                   //      V      Same here
  25.             collision.gameObject.GetComponent<MeleeEnemyAI>().playerInRange = false;
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement