- Home /
Question by
darkpivotstudios · Jul 25, 2013 at 11:42 PM ·
c#if-statements
Check playerAlive var on if statement. "Error: Operator &&' cannot be applied to operands of typebool' and `int'"
So I have a script where the player collides with an enemy, it will disable its rendering for a short period of time before it "respawns". I want to make it so the player can not be hit again while it's already dead.
This is my current code:
if(collider.gameObject.CompareTag("Enemy"))
{
playerLives--;
renderer.enabled = false;
timer = Time.time;
}
I have a variable "playerAlive" which = 1. I want to have it also check if playerAlive = 1 on the if statement, but I can't figure out how. I tried this:
if(collider.gameObject.CompareTag("Enemy") && (playerAlive = 1))
{
playerLives--;
renderer.enabled = false;
timer = Time.time;
}
but I get an error saying:
Operator
&&' cannot be applied to operands of type
bool' and `int'
How should I do this properly?
Comment
Best Answer
Answer by Benproductions1 · Jul 25, 2013 at 11:47 PM
Hello,
When checking wether two values are equal, you use ==
.
If you want to assign a value to something, you use =
.
if (5.0 == 5) {
//This is true
}
if (5.0 = 5) {
//This throws an error
}
Hope this helps,
Benproductions1