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);
}
}
},