Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

I Need Help For making an coin picking Script *Please Help!!*

Discussion in 'Scripting' started by SoulBlaze06, Dec 15, 2020.

  1. SoulBlaze06

    SoulBlaze06

    Joined:
    Sep 25, 2020
    Posts:
    4
    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-3) 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. It just destroys my voin after triggering but never updates the score

    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 . I am new to unity . i am using unity for 1 month now that means i am very new to coding and unity. If anybody knows how to make this work please help me please. Please give me a working script and tell me how it works pleaseee.
     
    Last edited: Dec 15, 2020
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    Oh really??

    Screen Shot 2020-12-15 at 10.23.44 AM.png
    Take a deep breath, work through at least two of the tutorials. This is monkey-simple basic stuff, but the code is perhaps only 25% of the problem: the scene(s) and prefab(s) have to be set up just so.

    When you have a SPECIFIC question, here is how to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220
     
  3. SoulBlaze06

    SoulBlaze06

    Joined:
    Sep 25, 2020
    Posts:
    4
    ok thanks but i fixed it using static keyword