Question by
Sheath9 · Jul 21, 2017 at 09:57 AM ·
c#gameobjectbeginnergameobject.findgameobject
How do i convert game object counts, into int, and put into string?
In the game i'm working on, the player collects diamonds; prefab gameobjects, already tagged as 'Diamond' in the level. I am having trouble trying to get the amount of gameobjects in the scene, convert that amount into an int, and display the int number on the screen as a string.
Since I am a beginner in programming, I have only been able to piece together code and see what works by trial and error, but this keeps feeding me back the error "connot convert type gameobject to int"... or something like that.
Here is my current script I am working on:
public int numDiamonds = 0;
GameObject[] diamondsinlevel = GameObject.FindGameObjectsWithTag("Diamond").Length;
public int DiamondsInLevel = diamondsinlevel;
void Start () { }
void Update () {
numDiamonds = DiamondsInLevel;
}
private void OnGUI()
{
GUI.Label(new Rect(1, 1, 200, 30), "Diamonds Left: " + numDiamonds);
}
Comment
Your answer
Follow this Question
Related Questions
Cascading dropdown menus 0 Answers
How do you activate a game object ? 1 Answer
How clone prefab and change it with not change original 0 Answers