hola tengo estoy haciendo un juego en unity estilo tower attack en el que poodes mandar oleadas de bichos a atacar una ciudad
el problema es que podes llegar a tener 200 o mas bichos en pantalla y anda re lento, desactive vsinc use spite package no uso getcomponen un ninguna parte del codigo pues en el start de cada objeto referencio todas las cosas que valla a usar asi no estoy entrando a la funcion constantemente, y son Gameobjects con colliders y un GamObject de hijo con otro collider todos con rigidbody kinematic, cuando tengo 40 bichos en pantalla se empieza a arrastras incluso en pc,
si alguno tiene idea de que puedo hacer o que puede ser el problema estaria agradecido xD
aca dejo los scripts:
ScriptGoblin
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Goblin : MonoBehaviour
{
//Monitoring
internal EventManager eventManager;
//States
protected int iddleState = 0;
protected int movePointState = 1;
protected int moveTargetState = 2;
protected int attackTargetState = 3;
protected int stopAttackState = 4;
protected int dieState = 5;
//private int initState = 0;
public int currentState = 0;
public int beforeState = 0;
//Stats
public string nameGoblin;
[HideInInspector]
public string personalName;
public float beerAdware;
public string type;
public float velocity = 40;
public float hp = 7;
public float hpMax;
public float damage = 10;
[HideInInspector]
public int defence;
public int defenceVsMele;
public int defenceVsArrows;
//Attack
public int tipoGobinsRango = 0;
public int typeAttack = 1;
internal int originTypeAttack;
public float attackCoolDown = 1;
internal bool canAttack = true;
public bool attacking = false;
internal float attackTimer = 0;
public int rangoAtaque = 100;
//Movement
private bool nextWaypointAfterAttack;
public GameObject pathObject;
protected Transform nextPoint;
protected Transform wayPoints;
public int wayPointIndex = 0;
public Transform enemyAttacking;
//velMovement
internal float debuffVelocity;
internal float buffVelocity;
internal float velocityNow;
//damage
internal float debuffDamage;
internal float buffDamage;
internal float damageNow;
internal float damageRoyalWhip = 0;
//defence
internal float debuffDefence;
internal float buffDefence;
internal float defenceNow;
//Enemies
public bool moveToEnemy = true;
public Transform nearEnemy;
public bool enemyAssign;
public int animationState;
private bool imDie;
internal float oldX, oldY;
// [HideInInspector]
public float angleMove;
public bool habilityAnimation;
internal LevelState levelState;
internal bool royalWhip;
internal float royalWhipVelocity;
internal float timerRoyalWhip;
internal float durationRoyalWhip;
internal float prevVelocity;
[HideInInspector]
public bool abilityStandActive;
[HideInInspector]
public Animator animatorComponent;
private SpriteRenderer spriteRendererComponent;
public Transform myTransform;
public bool hit;
float timerHit;
float CDTimerHit = 0.5f;
bool positionAttackCorrect;
OnlyRider onlyRider;
OnlyWolf onlyWolf;
public PoolManager poolManager;
private void Awake()
{
spriteRendererComponent = GetComponent<SpriteRenderer>();
myTransform = GetComponent<Transform> ();
}
// Use this for initialization
void Start()
{
if(GetComponent<OnlyRider>())
{
onlyRider = GetComponent<OnlyRider> ();
}
if(GetComponent<OnlyWolf>())
{
onlyWolf = GetComponent<OnlyWolf> ();
}
poolManager = GameObject.Find("PoolManager").GetComponent<PoolManager>();
hpMax = hp;
animatorComponent = GetComponent<Animator>();
eventManager = GameObject.Find("EventManager").GetComponent<EventManager>();
levelState = GameObject.Find("LevelState").GetComponent<LevelState>();
originTypeAttack = typeAttack;
oldX = myTransform.position.x;
oldY = myTransform.position.y;
if (animatorComponent)
{
animatorComponent.Play("Walk", -1, Random.Range(0.0f, 1.0f));
}
FindNearPoint();
}
// Update is called once per frame
void Update()
{
if (levelState != null && !levelState.gamePaused)
{
//control of buffs and debuffs
//defenceNow = defence + debuffDefence + buffDefence;
damageNow = damage + debuffDamage + buffDamage;
RedHit();
if (prevVelocity == 0)
{
velocityNow = velocity + debuffVelocity + buffVelocity;
}
CdAttack();
if (enemyAttacking == null)
{
attacking = false;
}
RoyalWhipIsActive();
if (animatorComponent != null && !animatorComponent.enabled)
{
animatorComponent.enabled = true;
}
if (hp <= 0)
{
GetComponent<Collider2D>().enabled = false;
SetState(dieState);
}
if (animatorComponent)
{
AnimationUpdate();
}
//FindNearPoint();
if (GetcurrentState() == iddleState)
{
SetMovePointState();
}
else if (GetcurrentState() == movePointState)
{
MovementTarget(wayPoints);
}
else if (GetcurrentState() == moveTargetState)
{
MovementTarget(enemyAttacking);
}
else if (GetcurrentState() == attackTargetState)
{
AttackEnemy();
}
else if (GetcurrentState() == stopAttackState)
{
StopAttack();
}
else if (GetcurrentState() == dieState)
{
if (!animatorComponent)
{
Destroy();
}
}
}
else
{
if (animatorComponent != null && animatorComponent.enabled)
{
animatorComponent.enabled = false;
}
}
}
public float GetHpMax()
{
return hpMax;
}
public void DestroyObject()
{
AddDieToManager();
Invoke("Destroy", 1);
}
internal void Destroy()
{
Destroy(gameObject);
}
public void HealigBuff(int aHealt)
{
float temp = hp + aHealt;
if (temp <= hpMax)
{
hp += aHealt;
}
else
{
hp = hpMax;
}
}
//buffAndDebuffMethods
internal void AddVelocityBuff(float aBuffVel)
{
buffVelocity += aBuffVel;
}
internal void AddDamageBuff(float aDamageBuff)
{
buffDamage += aDamageBuff;
}
internal void AddDefenceBuff(int aGoblinDefenceBuff)
{
buffDefence += aGoblinDefenceBuff;
}
internal void AddDebuffVelocity(float aDebuffVel)
{
debuffVelocity -= aDebuffVel;
}
internal void AddDebuffDamage(float aDebuffDamage)
{
debuffDamage -= aDebuffDamage;
}
internal void AddDebuffDefence(float aDebuffDefence)
{
debuffDefence -= aDebuffDefence;
}
//funcion de unity cuando entro en collision con algo
private void OnTriggerEnter2D(Collider2D collision)
{
if (GetComponentInParent<Collider2D>().GetType() == typeof(BoxCollider2D))
{
//si choco contra el collider "StopGoblinMove" y ademas es el enemigo cercano
if (collision.name == "StopGoblinMove" && enemyAttacking != null && collision.transform.parent.gameObject == enemyAttacking.gameObject)
{
// me dejo de mover
moveToEnemy = false;
}
}
}
//habilidad del latigo
public void SetRoyalWhip(float aDurationEffect, float aBuffVelocity, float aDamage)
{
durationRoyalWhip = aDurationEffect;
royalWhipVelocity = aBuffVelocity;
damageRoyalWhip = aDamage;
AddDamageBuff(aDamage);
if (!royalWhip)
{
royalWhip = true;
}
}
public void RoyalWhipIsActive()
{
if (royalWhip && !abilityStandActive)
{
if (timerRoyalWhip == 0)
{
AddVelocityBuff(royalWhipVelocity);
}
timerRoyalWhip += Time.deltaTime;
if (timerRoyalWhip >= durationRoyalWhip)
{
AddDebuffVelocity(royalWhipVelocity);
timerRoyalWhip = 0;
if (damageRoyalWhip != 0)
{
AddDebuffDamage(damageRoyalWhip);
damageRoyalWhip = 0;
}
royalWhip = false;
}
}
}
public void SetVelZero()
{
prevVelocity = velocityNow;
velocityNow = 0;
}
public void SetVelNow()
{
velocityNow = prevVelocity;
prevVelocity = 0;
}
internal void AnimationUpdate()
{
if (GetcurrentState() != dieState)
{
//si me estoy moviendo
if (moveToEnemy)
{
if(positionAttackCorrect)
{
positionAttackCorrect = false;
}
//Flip sprite lateral
if (animationState == 0)
{
if (myTransform.position.x > oldX)
{
spriteRendererComponent.flipX = false;
}
else if (myTransform.position.x < oldX)
{
spriteRendererComponent.flipX = true;
}
}
if (habilityAnimation)
{
animationState = 6;
}
//1 movimiento arriba
else if ((angleMove >= 90 && angleMove < 135) || (angleMove <= 90 && angleMove >= 45))
{
animationState = 1;
}
//2 movimiento abajo
else if ((angleMove <= -90 && angleMove >= -135) || (angleMove >= -90 && angleMove <= -45))
{
animationState = 2;
}
//0 movimiento lateral
else if ((angleMove >= 135 && angleMove <= 180) || (angleMove >= -180 && angleMove <= -135) || (angleMove >= 0 && angleMove <= 45) || (angleMove <= 0 && angleMove >= -45))
{
animationState = 0;
}
}
//si no me muevo es porque estoy peleando
// 3 animacion ataque
else
{
if (enemyAttacking != null && !positionAttackCorrect && !moveToEnemy)
{
if (myTransform.position.x < enemyAttacking.transform.position.x)
{
spriteRendererComponent.flipX = false;
}
else if (myTransform.position.x > enemyAttacking.transform.position.x)
{
spriteRendererComponent.flipX = true;
}
positionAttackCorrect = true;
}
animationState = 3;
}
}
//4 animacion muerte
else
{
animationState = Random.Range(4, 6);
}
oldX = myTransform.position.x;
oldY = myTransform.position.y;
animatorComponent.SetInteger("State", animationState);
}
//me muevo hacia un destino
public void MovementTarget(Transform aDestiny)
{
if (aDestiny != null)
{
Vector3 direction = aDestiny.position - myTransform.localPosition;
float distanceInFrames = velocityNow * Time.deltaTime;
angleMove = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
if (aDestiny.tag == "Enemy" || aDestiny.tag == "Die")
{
if (tipoGobinsRango == 0)
{
if (direction.magnitude > distanceInFrames && moveToEnemy)
{
// entonces sigo moviendome
if (!animatorComponent.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
{
myTransform.Translate(direction.normalized * distanceInFrames, Space.World);
}
}
else
{
FindNearPoint();
moveToEnemy = false;
SetState(attackTargetState);
}
}
else if (tipoGobinsRango == 1)
{
if (aDestiny.GetComponent<Barrel>())
{
if (direction.magnitude > distanceInFrames && moveToEnemy)
{
if (!animatorComponent.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
{
myTransform.Translate(direction.normalized * distanceInFrames, Space.World);
}
}
else
{
FindNearPoint();
moveToEnemy = false;
SetState(attackTargetState);
}
}
else
{
if (direction.magnitude - rangoAtaque > distanceInFrames && moveToEnemy)
{
if (!animatorComponent.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
{
myTransform.Translate(direction.normalized * distanceInFrames, Space.World);
}
}
else
{
moveToEnemy = false;
SetState(attackTargetState);
}
}
}
}
else
{
moveToEnemy = true;
if (direction.magnitude > distanceInFrames)
{
if (!animatorComponent.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
{
myTransform.Translate(direction.normalized * distanceInFrames, Space.World);
}
}
else
{
if (wayPointIndex+1 > pathObject.transform.childCount - 1)
{
if (!imDie)
{
SetDieState();
imDie = true;
}
}
else
{
wayPointIndex++;
FindNearPoint();
}
}
}
}
else
{
if (attacking)
{
SetStopAttackState();
}
else
{
//FindNearPoint();
SetMovePointState();
}
}
}
//ataca al enemigo y marca a donde ir despues del ataque
public void AttackEnemy()
{
AttackCoolDownTimer();
}
//reinicia el contador
private void AttackCoolDownTimer()
{
if (enemyAttacking == null || enemyAttacking.transform.tag == "Die")
{
if (enemyAttacking != null)
{
enemyAttacking = null;
nearEnemy = null;
}
moveToEnemy = true;
enemyAssign = false;
FindNearPoint ();
SetState(stopAttackState);
}
else if (nearEnemy != enemyAttacking && nearEnemy != null)
{
moveToEnemy = true;
enemyAssign = false;
SetState(moveTargetState);
}
else if (attacking)
{
if ((canAttack) && (onlyRider!=null || onlyWolf!=null))
{
if (enemyAttacking != null)
{
if (tipoGobinsRango == 0)
{
enemyAttacking.GetComponent<Enemy>().Hit(damageNow);
CountTotalDamage();
canAttack = false;
}
}
else
{
return;
}
}
}
}
public void HitEnemy()
{
if (attacking)
{
if (enemyAttacking != null)
{
if (tipoGobinsRango == 0)
{
enemyAttacking.GetComponent<Enemy>().Hit(damageNow);
CountTotalDamage();
canAttack = false;
}
}
else
{
return;
}
}
}
//detiene el ataque
public void StopAttack()
{
attacking = false;
moveToEnemy = true;
enemyAssign = false;
//FindNearPoint();
SetState(movePointState);
}
private void CdAttack()
{
// si no puedo pegar reinicio el contador
if (!canAttack)
{
attackTimer += Time.deltaTime;
// si paso el tiempo de cooldown puedo volver a atacar
if (attackTimer >= attackCoolDown)
{
canAttack = true;
attackTimer = 0;
}
}
}
//control de daño y vida del objeto
public void Hit(float aDamage, int aType)
{
GameObject floating = poolManager.GetGoblinText();
floating.transform.position = new Vector3(myTransform.position.x, myTransform.position.y + 70, myTransform.position.z);
floating.SetActive(true);
//aType 1 melee, 0 arrows
hit = true;
if (aType == 1)
{
defence = defenceVsMele;
}
else if (aType == 0)
{
defence = defenceVsArrows;
}
if (defence == 0)
{
floating.GetComponent<FloatingNumbers>().SetDamageNumber((int)aDamage);
hp -= Mathf.Abs(aDamage);
}
else
{
floating.GetComponent<FloatingNumbers>().SetDamageNumber((int)((aDamage-(aDamage * defence) / 100)));
hp -= Mathf.Abs(aDamage - (aDamage * defence) / 100);
}
if (hp <= 0)
{
hp = 0;
SetState(dieState);
}
}
internal void RedHit()
{
if (hit)
{
timerHit += Time.deltaTime;
spriteRendererComponent.color = new Color(0.96f, 0.63f, 0.63f, 1);
if (timerHit >= CDTimerHit)
{
spriteRendererComponent.color = Color.white;
timerHit = 0;
hit = false;
}
}
}
//control de daño y vida del objeto
public void HitPenetration(float aDamage, float aArmorPenetration)
{
if (defenceNow == 0)
{
hp -= aDamage;
}
else
{
float defenceTemp = defenceNow - aArmorPenetration;
if (defenceTemp < 0)
{
defenceTemp = 0;
}
hp -= aDamage - (aDamage * defenceTemp) / 100;
}
if (hp <= 0)
{
hp = 0;
SetState(dieState);
}
}
//setear estado
internal void SetState(int aState)
{
if (aState == dieState)
{
myTransform.tag = "Die";
}
if (beforeState != aState)
{
beforeState = aState;
}
if (currentState != aState)
{
FindNearPoint ();
currentState = aState;
}
if (aState == movePointState)
{
enemyAssign = false;
moveToEnemy = true;
}
//antes de cambiar de estado acomodo las variables necesarias del ataque
if (aState == moveTargetState)
{
Attack();
}
}
//Busca el punto mas cercano
public void FindNearPoint()
{
//moveToEnemy = true;
if (pathObject != null)
{
if (wayPointIndex <= pathObject.transform.childCount - 1)
{
var distActual = Vector3.Distance(pathObject.transform.GetChild(wayPointIndex).position, myTransform.localPosition);
int index = wayPointIndex;
for (int i = wayPointIndex; i < pathObject.transform.childCount - 1; i++)
{
var dist = Vector3.Distance(pathObject.transform.GetChild(i).position, myTransform.localPosition);
if (dist < distActual)
{
distActual = dist;
index = i;
}
}
wayPoints = pathObject.transform.GetChild(index);
}
else
{
//esto funciona pero antes no deberia de estar entrando a este else mas de 1 vez, revisar por que pasaba eso.
if (!imDie)
{
SetDieState();
imDie = true;
}
}
}
}
//obtener estado
public int GetcurrentState()
{
return currentState;
}
public void SetOutState()
{
SetState(-1);
}
internal void Attack()
{
if (enemyAttacking != nearEnemy && !enemyAssign)
{
enemyAttacking = nearEnemy;
enemyAssign = true;
attacking = true;
if (enemyAttacking != null && enemyAttacking.GetComponent<HumanManager>())
{
enemyAttacking.GetComponent<HumanManager>().goblinAttackingMe = true;
}
}
}
//setear enemigo cercano
public void SetNearEnemy(Transform aNearEnemy)
{
nearEnemy = aNearEnemy;
}
public void SetAttackEnemy(Transform aEnemyAttacking)
{
enemyAttacking = aEnemyAttacking;
}
//obtener enemigo cercano
public Transform GetNearEnemy()
{
return nearEnemy;
}
//obtener tipo de ataque
public int GetTypeAttack()
{
return typeAttack;
}
//setea los caminos
public void SetPathObject(GameObject aPath)
{
pathObject = aPath;
}
//devuelve los caminos para el goblin
public GameObject GetPathObject()
{
return pathObject;
}
public void SetOriginalAttack()
{
typeAttack = originTypeAttack;
}
public string GetPersonalName()
{
return personalName;
}
public void SetPersonalName(string aPersonalName)
{
personalName = aPersonalName;
}
internal void CountTotalDamage()
{
if (type == "Looter")
{
eventManager.TotalDamageLooters += damageNow;
}
else if (type == "Shielder")
{
eventManager.TotalDamageShielders += damageNow;
}
else if (type == "Cooper")
{
eventManager.TotalDamageCoopers += damageNow;
}
else if (type == "Harasser")
{
eventManager.TotalDamageHarasser += damageNow;
}
else if (type == "Vulture")
{
eventManager.TotalDamageVultures += damageNow;
}
}
private void AddDieToManager()
{
if (type == "Looter")
{
eventManager.LootersDie++;
}
else if (type == "Shielder")
{
eventManager.ShieldersDie++; ;
}
else if (type == "Cooper")
{
eventManager.CoopersDie++;
}
else if (type == "Harasser")
{
eventManager.HarasserDie++;
}
else if (type == "Vulture")
{
eventManager.VulturesDie++;
}
}
/*---------------------------------------------------------------------*/
//setter publico de estados
public void SetIddleState() { SetState(iddleState); } // 0
public void SetMovePointState() { SetState(movePointState); } // 1
public void SetMoveTargetState() { SetState(moveTargetState); } // 2
public void SetAttackTargetState() { SetState(attackTargetState); } // 3
public void SetStopAttackState() { SetState(stopAttackState); } // 4
public void SetDieState() { SetState(dieState); } // 5
//getter publico de estados
public int GetIddleState() { return iddleState; } // 0
public int GetMovePointState() { return movePointState; } // 1
public int GetMoveTargetState() { return moveTargetState; } // 2
public int GetAttackTargetState() { return attackTargetState; } // 3
public int GetStopAttackState() { return stopAttackState; } // 4
public int GetDieState() { return dieState; } // 5
/*---------------------------------------------------------------------*/
}
ScriptEnemyManager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyManager : MonoBehaviour
{
public List<GameObject> nearEnemies;
private LevelState levelState;
private Goblin goblinComponent;
float timer;
// Use this for initialization
void Start()
{
goblinComponent = GetComponent<Goblin>();
levelState = GameObject.Find("LevelState").GetComponent<LevelState>();
}
// Update is called once per frame
void Update()
{
if (levelState != null && !levelState.gamePaused)
{
timer += Time.deltaTime;
if (timer>=0.25f)
{
UpdateNearEnemy();
UpdateEnemiesList();
timer = 0;
}
}
}
private void UpdateNearEnemy()
{
// si la lista de enemigos no esta vacia
if (nearEnemies.Count != 0)
{
// si la lista de enemigos cercanos no esta vacia || no estoy en estado de AttackTargetState() (atacando a un objetivo)
if (goblinComponent.GetNearEnemy() == null || goblinComponent.GetcurrentState() != goblinComponent.GetAttackTargetState())
{
//recorro la lista de neemigos cercanos
for (int i = 0; i < nearEnemies.Count; i++)
{
// si el enemigo del indice[i] no esta null o muerto o disble
if (nearEnemies[i] != null && nearEnemies[i].tag != "Die")
{
//si soy del tipo de ataque 1 (1 vs 1)
if (goblinComponent.GetTypeAttack() == 1)
{
//si el enemigo del inidce[i] es de tipo 1 y no tengo a nadie atacandome
if ((nearEnemies[i].GetComponent<Enemy>().typeEnemy == 1 && !nearEnemies[i].GetComponent<Enemy>().goblinAttackingMe && !GetComponent<Goblin>().attacking) ||
(nearEnemies[i].GetComponent<Enemy>().typeEnemy == 2 && !nearEnemies[i].GetComponent<Enemy>().goblinAttackingMe && !GetComponent<Goblin>().attacking))
{
//prendo la bandera que me estan atacando
nearEnemies[i].GetComponent<Enemy>().goblinAttackingMe = true;
//me paso el transform del goblin que me ataca
nearEnemies[i].GetComponent<Enemy>().AttackTarget(transform);
// le pongo como objetivo al goblin que me ataca mi transform
goblinComponent.SetNearEnemy(nearEnemies[i].transform);
goblinComponent.SetMoveTargetState();
return;
}
}
// si soy del tipo 2 (Patotero)
else if (goblinComponent.typeAttack == 2)
{
// pregunto si el tipo de Goblin del indice[i] es igual a 1 (1 vs 1)
if ((nearEnemies[i].GetComponent<Enemy>().typeEnemy == 1 && !GetComponent<Goblin>().attacking) ||
(nearEnemies[i].GetComponent<Enemy>().typeEnemy == 2 && !GetComponent<Goblin>().attacking))
{
//prendo la bandera que me estan atacando
nearEnemies[i].GetComponent<Enemy>().goblinAttackingMe = true;
// me pongo como enemigo cercano el Goblin del indice[i]
goblinComponent.SetNearEnemy(nearEnemies[i].transform);
//le pongo al Goblin como enemigo cercano mi posicion
//nearEnemies[i].GetComponent<Enemy>().AttackTarget(transform);
goblinComponent.SetMoveTargetState();
return;
}
}
// si soy del tipo 3 ataca a lo primero que encuentra
else if (goblinComponent.typeAttack == 3)
{
if (!goblinComponent.attacking)
{
//prendo la bandera que me estan atacando
nearEnemies[i].GetComponent<Enemy>().goblinAttackingMe = true;
// me pongo como enemigo cercano el Goblin del indice[i]
goblinComponent.SetNearEnemy(nearEnemies[i].transform);
//le pongo al Goblin como enemigo cercano mi posicion
// nearEnemies[i].GetComponent<Enemy>().AttackTarget(transform);
goblinComponent.SetMoveTargetState();
return;
}
}
}
}
// recorro la lista de enemigos cercanos
for (int i = 0; i < nearEnemies.Count; i++)
{
// si el enemigo del indice[i] no es null && enemigo del indice[i] es del tipo 0 (solo corre (cagon pecho frio xD) )
if (nearEnemies[i] != null && nearEnemies[i].tag != "Die" && nearEnemies[i].GetComponent<Enemy>().typeEnemy == 0 && !GetComponent<Goblin>().attacking)
{
// le marco mi posicion de enemigo cercano al Goblin
goblinComponent.SetNearEnemy(nearEnemies[i].transform);
return;
}
}
}
}
else
{
goblinComponent.SetNearEnemy(null);
}
}
private void UpdateEnemiesList()
{
if (nearEnemies != null)
{
for (int i = 0; i < nearEnemies.Count; i++)
{
if (nearEnemies[i] == null)
{
nearEnemies.Remove(nearEnemies[i]);
}
}
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Enemy" && !GetComponent<HumanArcher>())
{
nearEnemies.Add(collision.gameObject);
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.tag == "Enemy")
{
nearEnemies.Remove(collision.gameObject);
if (collision.GetComponent<Enemy>().target == transform)
{
collision.GetComponent<Enemy>().target = null;
}
}
}
}
RangerGoblin
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RangeGoblins : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.transform.parent!=null && collision.transform.parent.tag == "Enemy" && collision.name=="StopGoblinMove")
{
GetComponentInParent<EnemyManager>().nearEnemies.Add(collision.transform.parent.gameObject);
}
}
}