I am using an if else statement to calculate the players accuracy from the targets he/she manages to hit as shown below very basically. if the player hits barrel1 then variable br1 is updated in a different gameobject holding the values to calculate the accuracy. A problem I’m having is that even when the player hits the first barrel both variables br1 and br miss are updated. I think the first and second if statements are seperated so i would like to use and if else if statement but doesn’t seem to work. any ideas?
if(hit.collider.gameObject.tag=="barrel")
{
GameDataScript gamedatascript= gameData.GetComponent<GameDataScript>();
gamedatascript.br1+=1;
}
if(hit.collider.gameObject.name=="barrel2")
{
GameDataScript gamedatascript= gameData.GetComponent<GameDataScript>();
gamedatascript.br2+=1;
}
else
{
GameObject gameData = GameObject.Find("GameData");
GameDataScript gamedatascript= gameData.GetComponent<GameDataScript>();
gamedatascript.brmiss+=1;
}
}