Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Count the contents of the list from FindGameObjectsWithTag

$
0
0
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()); } }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>