Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
Why can't gameobject in the hierarchy find it without problems? Solved

I want to find the GameObject that is in the hierarchy correctly in the hierarchy. But this does not happen correctly, so I want 'if' to work when the gameobject I have tagged is active, but 'if' works even though there is no other gameobject tag, which is why this problem is caused.

Note: My level of English is not good, I try to explain the problem to you as much as I can, please tell me if there is anything you do not understand, I will try to explain it in detail as much as I can. Thank you for your understanding.

  1. Image tagged gameobject: enter image description here
  2. The point where the problem occurred: enter image description here
  3. Gameobject tag name: enter image description here
  4. Cubes Gameobject: enter image description here
    void Update()
    {
        if (cubes.instance.objPool.Count == 1) //It works when the number of gameobject in the list is 1 when I do a random deletion.
        {
            RewardSystem();
        }
    }
 
 
public void RewardSystem()
    {
        GameObject FoundCube = GameObject.FindGameObjectWithTag(cube_Tag_Number);
 
 
        if (FoundCube == null)
        {
            SoundManager.instance.GameOverMenuSound();
            game_Over_Menu.SetActive(true);
 
            next_Level_Menu.SetActive(false);
            confetti.Stop();
            clickButton.gameObject.SetActive(false);
            missionButton.gameObject.SetActive(false);
            enabled = false;
        }
        if (FoundCube != null)// problematic if
        {
            if (FoundCube.activeInHierarchy == true) // problematic if
            {
                SoundManager.instance.NextLevelMenuSound();
                next_Level_Menu.SetActive(true);
                confetti.Play();
 
                game_Over_Menu.SetActive(false);
                clickButton.gameObject.SetActive(false);
                missionButton.gameObject.SetActive(false);
                enabled = false;
            }
        }
    }
 
 
public class cubes : MonoBehaviour
{
    public static cubes instance;
 
    public int randomRangeNumber1, randomRangeNumber2;
 
    public List<GameObject> objPool = new List<GameObject>();
 
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != null)
        {
            Destroy(gameObject);
        }
 
    }
 
    public void ButtonOnDown()
    {
        SoundManager.instance.LuckButtonSound();
 
         for (int i = 0; i < 1; i++)
         {
            int index = Random.Range(randomRangeNumber1, randomRangeNumber2);
            GameObject.Destroy(objPool[index]);
            objPool.RemoveAt(index);
 
            randomRangeNumber2 = objPool.Count;
         }
    }
}
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!