简体   繁体   中英

Scoring system collect item not updating Text UI - Unity C#

I have created 2 scripts one which handles the collection of the item and another which handles the score being displayed to the screen. Currently the sound plays and the item is destroyed onTriggerEnter but the score's UI-Text does not update. I have tried to add the score inside ScoringSystem and CollectGem both scripts are below.

ScoringSystem is attached to a GameObject with TextScore assigned to the slot.

Can anybody see why the text would not be adding 1 on collection?

CollectGem

public class CollectGem : MonoBehaviour
{
    public AudioSource collectNoise;

    public void OnTriggerEnter(Collider collider)
    {
        collectNoise.Play();
        ScoringSystem.theScore += 1;
        Destroy(gameObject);
    }
}

Scoring System

public class ScoringSystem : MonoBehaviour
{
    public GameObject score;
    public static int theScore;

    void update()
    {
        score.GetComponent<Text>().text = "Gems: " + theScore;
    }
}

Careful, spelling matters very much in our code.

void update() != void Update()

Seems like you just forgot to capitalize the name of "Update" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM