Hello, I am trying to make an enemy that has a child game object become set active false but I have many other enemies with the same name so I don’t want to have the compiler confused which enemy that is doing the attacking and mistaken that all of them are.
So how I am trying to avoid this is by making the scripts communicate each other within the same gameobject (if that make sense). I feel this is very simple but I can’t fathom what I am missing or forgetting. I would appreciate any help because lord knows I need. Thanks in advance. Here is the script I am working on to show a little more what I am trying to do.
using UnityEngine;
using System.Collections;
public class EnemyAIMelee : MonoBehaviour
{
private bool AttackStatus;
public float attackDistance = 5.0f;
public float chaseSpeed = 0.01f;
private bool unlockAI;
public GameObject playerCharacterManager;
// Use this for initialization
void Start()
{
playerCharacterManager = GameObject.FindGameObjectWithTag ("PlayerCharacterManager");
AttackStatus = false;
unlockAI = true;
}
// Update is called once per frame
void Update ()
{
if (AttackStatus == true)
{
MovingAI ();
}
}
void MovingAI()
{
if(unlockAI == true)
{
transform.rotation = Quaternion.LookRotation(transform.position - playerCharacterManager.transform.position);
transform.position = Vector3.MoveTowards (transform.position, playerCharacterManager.transform.position, chaseSpeed);
Debug.Log ("MovingAI has been reached");
SendMessage ("EnemyMovingAnimation", true);
float distance = Vector3.Distance(playerCharacterManager.transform.position, transform.position);
if(distance<=attackDistance)
{
SendMessage ("EnemyMovingAnimation", false);
StartCoroutine("AttackAI");
Invoke("InstantiateEnemyPunchBox",0.5f);
}
}
}
IEnumerator AttackAI()
{
unlockAI =false;
SendMessage ("EnemyAttackAnimation", true);
yield return new WaitForSeconds (1.0f);
SendMessage ("EnemyAttackAnimation", false);
Debug.Log ("AttackAI has been reached");
yield return new WaitForSeconds (4.0f);
unlockAI = true;
}
void InstantiateEnemyPunchBox()
{
//Have the child game object, attached to the game object this script is being put on, become set active
}
void BeginTheAttack(bool chase)
{
AttackStatus = chase;
}
}