- Home /
(C#) My enemy dosent take damage ScriptFix
public class DestroyScript : MonoBehaviour {
public float lifetime = 1.0f;
void Start ()
{
}
void Update () {
}
void Awake ()
{
Destroy (gameObject,lifetime);
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Enemy")
{
//other.gameObject.GetComponent<>().EnemyCurHealth = EnemyCurHealth - 30;
DestroyObject(other.gameObject);
Destroy(gameObject);
}
}
}
I think the problem is on the "//" line cuz im getting errors all the time and i dont know what it is i need in it. i know i need GetComponent to get the health script (The health is just an int) and after i need an
if(EnemyCurHealth = 0)
{
Destroy(gameObject);
}
But can anyone see what i need to do befor?
EDIT: //other.gameObject.GetComponent().EnemyCurHealth = EnemyCurHealth - 30; as a <>script but it wont show in the question somehow
Answer by Lovrenc · Apr 09, 2013 at 12:59 PM
other.gameObject.GetComponent().EnemyCurHealth = EnemyCurHealth - 30;
Get WHAT component?? ForInstance:
other.gameObject.GetComponent<EnemyScript>().EnemyCurHealth = EnemyCurHealth - 30;
I have GetComponent<> but it wont show in the question. Dont know how, so thats not the problem
Your answer
Follow this Question
Related Questions
Damage on collision with player.. 1 Answer
Multiple Cars not working 1 Answer
My enemy wont take damage 0 Answers
Enemy Targetting Help 1 Answer