I'm trying count the number of elements in the list generated by "GameObject.FindGameObjectsWithTag("soldier")" so that I can use the result to alter the addscore variable. Maybe I've been looking the places but none of the answers I've found have worked.
using UnityEngine;
using System.Collections;
public class resourceGUI : MonoBehaviour {
private float score = 0;
private float addscore;
public GameObject unit;
private GameObject tax;
void Start () {
InvokeRepeating("EachSecond", 0, 1);
}
// Update is called once per frame
void Update () {
GameObject[] tax;
tax = GameObject.FindGameObjectsWithTag("soldier");
addscore=10-tax;
}
void EachSecond(){
score=score+addscore;
}
void OnGUI(){
GUI.Box(new Rect(10,10,100,20), score.ToString());
}
}
↧