Question by
frankjstrike · Aug 29, 2015 at 01:59 PM ·
boolvoid
Cannot implicitly convert type 'void' to 'bool'
For some reason when i try to call for a method in my if statement it gives me the error " Cannot implicitly convert type 'void' to 'bool'". How can i fix this??
Here is my code:
public class Player : MonoBehaviour {
private bool checkpointEnabled = false;
public static Vector3 checkpoint;
public static Vector3 respawn;
void Start () {
spawn = transform.position;
checkpoint = gameObject.transform.position;
respawn = spawn;
}
void FixedUpdate () {
if (checkpointEnabled)
{
respawn = checkpoint;
}
if (Die())
{
if(checkpointEnabled)
{
transform.position = respawn;
}
}
}
void Die()
{
Instantiate(deathParticles, transform.position,Quaternion.Euler(0,0,0));
transform.position = spawn;
}
}
This is the part that is giving me the error.
if (Die())
{
if(checkpointEnabled)
{
transform.position = respawn;
}
Comment
Answer by Dave-Carlile · Aug 29, 2015 at 02:06 PM
Your Die
function returns void, not bool, so you can't use it in an if
statement.
Your Die function also doesn't do anything to check if a player should die, it just instantiates particles and sets the position.