Hi Everone,
I’m just learning unity and basing on tutorial game “Roll a ball” I’m trying hide more objects (ground and walls) after collected Pick Ups. I can’t do this. I tried type code in SetCountText() function or OnTriggerEnter but-ofcourse-not work.
void OnTriggerEnter(Collider other)
{
// ..and if the game object we intersect has the tag 'Pick Up' assigned to it..
if (other.gameObject.CompareTag("Pick Up"))
{
// Make the other game object (the pick up) inactive, to make it disappear
other.gameObject.SetActive(false);
// Add one to the score variable 'count'
count = count + 1;
Debug.Log("1");
if (count >= 2)
Debug.Log("2");
{
if (other.gameObject.CompareTag("platform1"))
{
Debug.Log("3");
other.gameObject.SetActive(false);
}
}
}
}
To "Debug.Log (“1”) everything is like in original, to “2” is ok - value “count = 2” is checked, but from then nothing happens. "Debug.Log 3 never show in console.
Why?
How can I hiding objects?
Well, if you look closely, you have two CompareTag. One is “Pick Up” the other is “platform1”.
Since objects can’t have two tags, the second doesn’t work. Generally speaking, it isn’t going to be a good idea to have to compareTag to a bunch of different tags, but if you’re just playing around, it isn’t going to be a big deal.
Just move the second compareTag outside of the first to start.
The other issue may be that the platform still will not be removed if it isn’t setup properly. Your pickups are probably setup as trigger colliders I’m guessing, but your platforms wouldn’t be. Removing platforms is probably not what you want for this.
Honestly, what you’re trying to do, you might just need to dig in and take the time to understand what the code does.
Brathnann,
I have two objects with two others tags. It is some with “other.object” and “object” because I can hide ball after collect 2 object with “pick ups” tag. Ball is without tag’s.
Your “honestly” advice sounds like motivation moral. Thanks, but I don’t need motivation. I need help with this code.
Lol… Did you just tell him, “hey, I don’t need to figure out the code, that’s why I’m asking you guys!” 
Sorry…
Onto your question… I think perhaps you want to create a reference to your ‘platform1’ game object, then remove the tag check for it. You’re already checking for the pick up, and you want to hide the platform when you’ve reached a count.
It would look something like this:
- create variable for platform1. drag n drop in the inspector
- pick up item? Yes, okay … add count.
- check if count >= 2, and if so, disable the platform1 game object.