Question by
TimeCastle · Nov 09, 2015 at 06:50 PM ·
c#uitext
Access parts of different scripts?
I need to access a script within another script, but I can't figure out how. I have a simple script that displays the current round, like so
using UnityEngine;
using System.Collections;
public class GUITextHandler : MonoBehaviour
{
public GameObject gui;
static int score;
void update()
{
gui.GetComponent ("GUIText").text = "Score: " + score;
}
}
this is supposed to change the GUIText component to whatever I set it to.
then I have another script that launches a function called "WaveEnded" whenever the wave ends.
what do I put in the "WaveEnded" function to make it so whenever the wave ends, the "score" goes up by 1?
Thanks very much for your time
Comment
Don't forget to name your update function Update with a capital U for it to execute.
Answer by Statement · Nov 09, 2015 at 07:09 PM
static int score;
Change that to
public static int score;
To be able to access it from WaveEnded:
void WaveEnded()
{
GUITextHandler.score++;
}