Switching Target
Hi guys, having a bit of an issue with something that I am fairly sure is quite easy to fix, essentially I am making a clone so when the player clicks a button, they instantiate a look-alike that the enemies target, for some reason it won't update if the button is pressed/ the timer runs out, here's the code so far, thanks :)
void Update(){
if (GetComponent<Taunt>().taunt == true){
clone = true;
}
if (GetComponent<Taunt>().taunt == false){
clone = false;
}
if (clone == false){
playerPos = GameObject.FindGameObjectWithTag("Player").transform;
}
if (clone == true){
playerPos = GameObject.FindGameObjectWithTag("PlayerClone").transform;
}
if (Vector2.Distance(transform.position, playerPos.position) > minRange){
transform.position = Vector2.MoveTowards(transform.position, playerPos.position, speed * Time.deltaTime);
}
else if (Vector2.Distance(transform.position, playerPos.position) <= minRange){
speed = 0f;
StartCoroutine(Delay());
}
if (GetComponent<EnemyHealthManager>().isDead == true || Dead == true){
Destroy(gameObject);
GameObject blood = Instantiate(bloodExplosion, transform.position, Quaternion.identity);
Destroy(blood, 0.1f);
GameObject splosion = Instantiate(effect, transform.position, Quaternion.identity);
Destroy(splosion, 0.1f);
}
}
Comment