Ok, after a few days I finally give up, so I come to you wise Unity community.
I have a player with weapons. When the player collides with a weapon on the ground it activates this process that I cant figure out how to do. Might need to read the next part a bit slower… sorry I’m confused too.
Upon collision the weapon on the ground checks if there is already a weapon with its tag in the transform that holds all of the weapons, holstered(inactive) and not(do not question my methods! hehe joking) and then if one of the children in that transform has its tag, it will give that child ammo and destroy it self, and if there isn’t a child with that tag, it will add it self to the transform with the rest of the weapons.
Now here’s where the problem starts.
If we have an if statement with “if a tag with my tag is there, add ammo to it and destroy it self” and an else if with “if a tag with my tag isn’t there, add self there” the second will always be true, because there will always be a child with a different tag in the transform. So that’s what I don’t know how to get around.
Here’s the basic layout of the code, to spare you the unnecessary details. Thanks for reading this far. xD
function OnTriggerEnter (other : Collider)
{
var triggered = true; //just a bool to make sure only one of the happens cause of said problem
if(other.gameObject.tag == "Player" && isPickup) //if collided with player and im a pickup
{
for (var child : Transform in playerCamera.transform)
{
if(child.gameObject.tag==myTag && triggered) //if weapon in players inventory is same tag as mine
{
//Add ammo code (leaving it out to keep it short)
}
else if(child.gameObject.tag!=myTag && triggered)
{
//Adds self to the inventory
}
}
}
}
Note: I tried DOZENS of variations with the if statements there combining some like if tag isnt my tag and if tag is my tag, and other combinations, but none worked out. I don’t know, instinct tells me I’m not using the “for” part right, but I don’t know how else to write it.
Thank you!