,i am also facing revelent issue.when my last box is destoryed the Gameobject.FindgameobjectwithTagg("done").length doesnot work propely

I have an issue with GameObject.FindGameObjectsWithTag (“done”).Length;. my script is attatched with 11 boxes that have a game object as child with same tag. when i hit box it is destroyed and decrements in length. when all the objects are destroyed it must show a panel. but panel is not activated at all. my code is as below

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AppleScript : MonoBehaviour
{
public GameObject CompletePanel;
public GameObject A,P;
public GameObject stingA,stingP;
[SerializeField]
int counterA;
void Start()
{
stingA.SetActive (false);
stingP.SetActive (false); }

//detect collision with trigger//
void OnTriggerEnter(Collider col)
{
	if (col.name == "colLB" || col.name == "colLF" || col.name == "colRB" || col.name == "colRF" || col.name == "colBody")
	{
		Debug.Log (this.gameObject.name);
		if(this.gameObject.name=="A")
		{
			Handheld.Vibrate ();
			//Debug.Log ("A.Active");
			A.SetActive (true);
			stingA.SetActive (true);
				//stingA.gameObject.GetComponent<Text> ().text = this.gameObject.name.ToString ();
			Destroy (A, 5);
		}

		if(this.gameObject.name=="P")
		{
			Handheld.Vibrate ();
			//Debug.Log ("P.Active");

			P.SetActive (true);
			//stingP.gameObject.GetComponent<Text> ().text = this.gameObject.name.ToString ();

			stingP2.SetActive (true);

			Destroy (P, 5);
		}
	}

}
void Update()
{
	counterA = GameObject.FindGameObjectsWithTag ("Alphatag").Length;
	Debug.Log ("countrA="+counterA);
	if (counterA==0) 
	{
		Debug.Log ("level Complete");
		CompletePanel.SetActive (true);
		Time.timeScale = 0;
		Debug.Log ("Destroyed counterA:"+counterA);
	}

}

},

1 Answer

1

Hello there,

You have multiple debug logs in there. Do they trigger? What do they say?

Your class is called AppleScript. That makes me think that these are the objects you are picking up and destroying? If that’s the case, your Update() function won’t be called because you are destroying the object it is attached to. If not, could you provide more information on this?

What object is this script attached to?