Hello everyone, I am having a doubt about Array and number, I have a scene where I am stuffing carton boxes into a container which is perfectly fine for me, but I need to add a few details to it, which is add a text which says how many boxes are remaining to load into the container can anyone please help me with this, Thank you in advance and I am adding my code and image below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Count : MonoBehaviour
{
public int remainingBox;
public bool isMoving;
public Text displayText;
public GameObject[] childCount;
void Start()
{
childCount = GameObject.FindGameObjectsWithTag("CartonBox");
}
void OnTriggerStay(Collider other)
{
// if(other.tag == "Door")
// {
displayText.text = remainingBox.ToString();
if (Input.GetMouseButtonDown(0) && !isMoving && remainingBox > 0 )
{
isMoving = true;
remainingBox --;
isMoving = false;
}
}
}