I have a problem "'void' cannot be used in a boolean context."

What i do wrong ?

sorry for poor english.

if(Input.GetButtonDown(“Fire1”))
{
var playerRay : RaycastHit ;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var onhitbar1 = GameObject.FindGameObjectWithTag(“Hit Bar”).GetComponent(HitBar);

if(Physics.Raycast(ray,playerRay))
{
if(onhitbar1.onHitBar1 == true)
{
Debug.Log(playerRay.collider.gameObject.tag);
if(playerRay.collider.gameObject.tag == “Food Bar” )
{
Destroy(GameObject.FindGameObjectWithTag(“Food Coin”));

if ( Destroy(GameObject.FindGameObjectWithTag(“Food Coin”)))
{
FoodPoint = FoodPoint + foP ;
}

onhitbar1.onHitBar1 = false;
score1++;
}
}
}

Please use tags to make your code easier to read.

Destroy return type is void, if () statement uses a boolean value. It means you can’t use Destroy() as a value for an if statement.

this is your error:

if ( Destroy(GameObject.FindGameObjectWithTag("Food Coin")))
{
FoodPoint = FoodPoint + foP ;
}

When you double click on an error in unity it opens your code editor and places the selection on the infringing line. Read what the error says and look at the line and you should be able to debug your code yourself.

Good luck with your game :slight_smile: