I’m not sure why, but for some reason I am getting an error for using “gameObject.layer = 8”, despite that being how the Unity Docs says to type it out. Any help would be appreciated, thank you!
void Update () {
if (health <= 0) {
Destroy (gameObject);
if (gameObject.layer = 8) {
score++;
Debug.Log("Enemy just died!");
}
}
}
because your using the set or single equals operator which makes something… something.
What you need to do is compare using the double equals operator
void Update () {
if (health <= 0) {
Destroy (gameObject);
if (gameObject.layer == 8) {
score++;
Debug.Log("Enemy just died!");
}
}
}
which says if the layer is equal to 8, wereas the other versions in the original post states, “set gameObject.layer to BE 8” which you can’t do in an if statement/block