So like I’ve spent the last hour searching around for how to fix this, and dispite writing down some peoples codes word for word character for character I can not figure this out.
So basically I have a bullet script, that makes the object move forward based on the objects public float, and a damage int to be applied to enemies.
public class bullet : MonoBehaviour {
public int damage;
public float velocity;
void Update () {
// bullet movement
transform.position += transform.right * Time.deltaTime * velocity;
}
// bullet dealing damage, then destroying itself
void OnCollisionEnter2D(Collision2D coll) {
if (coll.gameObject.tag == "Enemy")
coll.gameObject.GetComponent<EnemyHealth>().Health = Health - damage;
Destroy (gameObject);
}
}
it then in theory applies this damage effect to my enemy script:
public class EnemyHealth : MonoBehaviour {
public int Health;
void Update () {
if (Health => 0f)
{
Destroy (gameObject);
}
}
}
The bullet moves correctly and disapears on hit, but when I have the code to adjust the enemies health I get the error:
EnemyHealth.cs(10,7) error CS1660: Cannot convert ‘lambda’ to non-delegate type ‘bool’
There isn’t a single bool anywhere in this code so I have no idea what it’s talking about.
I also get the error:
bullet.cs(17,57): error CS0103: The name ‘Health’ does not exist in the current context
so yeah I’m at a loss, any ideas?
Edit:
Side note, I fixed the error “EnemyHealth.cs(10,7) error CS1660: Cannot convert ‘lambda’ to non-delegate type ‘bool’” simply by changing the “health <= 0” to health < 1" It basically works the same since it’s an int not a float, so that problem is fixed at least.