Hello , I tried so hard (and got so far) to make a Text say “Press H to buy health” when my points are superior to 1000 and “press h to buy health or G to upgrade your damage” when my points are over 3000 . When i press H or G (if i have points) it works but the text will not be there when i reach 1000 or 3000 .
Here is my text script
using UnityEngine.UI;
public class GearUp : MonoBehaviour {
private ScoreKeeper scoreKeeper;
private Text text;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (ScoreKeeper.score > 1000)
{
Text.print ("press H to buy life");
}
if (ScoreKeeper.score > 3000)
{
Text.print("press h to buy life Or G to upgrade your ship damage ");
}
}
}
now it works . I changed the ScoreKeeper script by adding a new integer that is equal to “points” (i’ve called it punti), and changed the GearUp script with ScoreKeeper.punti
(punti is the Italian word for points)
> ...
> > public class ScoreKeeper : MonoBehaviour {
> > public static int score = 0;
> > private Text mytext;
> > public int punti =score;
> > private void Start()
> > {
> > mytext= GetComponent<Text>();
> > Reset();
> > }
> >
> > public void Score(int points)
> > {
> > score += points;
> > mytext.text = score.ToString();
> > }
> > public static void Reset()
> > {
> > score = 0;
> > }
> > ...
and this is my new GearUp script:
…
public class GearUp : MonoBehaviour {
private Text text;
private ScoreKeeper scoreKeeper;
// Use this for initialization
void Start () {
Text text = GetComponent<Text>();
}
// Update is called once per frame
void Update () {
if (ScoreKeeper.punti > 1000)
{
text.text= ("premi H per comprare vita");
}
if (ScoreKeeper.punti > 3000)
{
text.text=("premi H per comprare vita o G per migliorare il danno ");
}
}
}
I just changed the if statement with the && and function so now it’s like this if (ScoreKeeper.score > 1000 &&ScoreKeeper.score<3000)
and if (ScoreKeeper.score > 3000 )
so now there is one true and one false (if i had 3000 point in the first code the first if was true and the second too so unity can’t change the text) .