I have an enemy that references a hero script!
a hero that references an enemy script!
towers that do damage to the enemy!
(All as objects the game works)
when I turn the enemy into a prefab and the hero and spawn enemies all the referenced scripts targets break, I relink them all in the prefabs and update
but then nothing works! the enemy doesn't take damage, ignores the hero!
What am I doing wrong :(
What I have tried:
Ive tried for days and searched the internet for answers!
Here is the enemy Code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine.Unity;
using Spine;
using UnityEngine.UI;
public class Enemy : MonoBehaviour
{
private bool Electrickcuted;
private bool WaterBombed;
private float electrickcuted = 2f;
private float HitByWater = 2f;
public EnemyMove moveScript;
public Police PoliceScript;
public SkeletonAnimation SkelAnim;
public float EnemyStartHealth =100;
public Image EnemyHealthBar;
public float Enemyhealth;
public GameObject HealthContainer;
[SpineAnimation]
public string walk;
[SpineAnimation]
public string electrick;
[SpineAnimation]
public string attack;
[SpineAnimation]
public string stand;
[SpineAnimation]
public string die;
[SpineAnimation]
public string water;
void Awake(){
SkelAnim = GetComponent<SkeletonAnimation>();
SkelAnim.state.SetAnimation(0,walk,true);
}
void Start()
{
Enemyhealth = EnemyStartHealth;
SkelAnim.state.SetAnimation(0,walk,true);
System.Random randomNumberGenerator = new System.Random();
int randomSkinNumber = randomNumberGenerator.Next(0, 60);
string skinName = "football_" + randomSkinNumber;
SkelAnim.skeleton.SetSkin(skinName );
}
public void TakeDamgeEnemy (float amount)
{
Enemyhealth -= amount;
EnemyHealthBar.fillAmount = Enemyhealth/EnemyStartHealth;
if (Enemyhealth <=0)
{
Destroy(GameObject.Find("TakeDamageEnemy"));
Destroy(GameObject.Find("HealthContainerEnemy"));
Destroy(GameObject.Find("enemyweapon"));
Destroy(GameObject.Find("EnemyFoot"));
moveScript.WalkSpeed = 0f;
WaterBombed = false;
Electrickcuted = false;
SkelAnim.state.SetAnimation(0,die,false);
}
}
private void Update()
{
if(Electrickcuted)
{
ElectrickAttack();
}
if(WaterBombed)
{
WaterAttack();
}
}
void OnTriggerEnter2D (Collider2D other)
{
if (other.gameObject.CompareTag("policeFootCol"))
{
SkelAnim.state.SetAnimation(0,attack,true);
moveScript.WalkSpeed = 0f;
TakeDamgeEnemy (0f);
}
if (other.gameObject.CompareTag("PoliceWeapon"))
{
TakeDamgeEnemy (10f);
}
if (PoliceScript.policehealth <=0)
{
PoliceScript.policehealth = 0;
SkelAnim.state.SetAnimation(0,walk,true);
moveScript.WalkSpeed = 1f;
}
if (other.gameObject.CompareTag("bullet"))
{
Electrickcuted = true;
SkelAnim.state.SetAnimation(0,electrick,true);
moveScript.WalkSpeed = 0f;
TakeDamgeEnemy (15f);
}
if (other.gameObject.CompareTag("WaterBomb"))
{
WaterBombed = true;
SkelAnim.state.SetAnimation(0,water,false);
moveScript.WalkSpeed = 0f;
TakeDamgeEnemy (20f);
}
}
private void ElectrickAttack()
{
if(electrickcuted < 0f)
{
Electrickcuted = false;
SkelAnim.state.SetAnimation(0,walk,true);
moveScript.WalkSpeed = 1f;
electrickcuted = 2f;
}else{
electrickcuted -= Time.deltaTime;
}
}
private void WaterAttack()
{
if(HitByWater< 0f)
{
WaterBombed = false;
SkelAnim.state.SetAnimation(0,walk,true);
moveScript.WalkSpeed = 1f;
HitByWater = 2f;
}else{
HitByWater -= Time.deltaTime;
}
}
}