Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How To Make A Coin Script Please help!

SoulBlazeSoulBlaze Member
edited December 2020 in Programming

Hi i am making an fps game . I added a coin prefab and want that when player collides with it it updates the text from (like 1- 2 then 2-30) and so on. I just want to have a working script which will allow me to pick coin and add 1 to score. I tried OnTriggerEnter but it only destroyed the coin after triggering it and i want to update the score by 1 too but my score(text) is not updating. i tried various things like these but nothing worked i am new to unity and programming . I has been 1 month since i am using unity. If someone knows please give me a working script and tell me how it worked. please.

using UnityEngine;

using System.Collections;

using System.Collections.Generic;

using UnityEngine.UI;


public Text text;

public int Score = 0;

void Update()

{

text.text = Score.ToString();

}

OnTriggerEnter(collider other)

{

Score++;

destroy(gameObject);

}

It is quiet difficult and there are no tutorials for it on youtube . If anybody knows how to make this work please help me please.

Answers

  • You need to update the text when the score changes

    Add

    text.text = Score.ToString();

    after Score++;

  • OnTriggerEnter(collider other)
    {
        Score++;
        text.text = Score.ToString();
        destroy(gameObject);
    }
    
Sign In or Register to comment.