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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Update text on collision

Discussion in 'Scripting' started by rudigreig, Apr 3, 2019.

  1. rudigreig

    rudigreig

    Joined:
    Dec 11, 2018
    Posts:
    50
    I have a collecting mission in my game, how can i make the text add 1 every time I collide with one? this is what i got so far...
    Code (CSharp):
    1. public class Tickets : MonoBehaviour
    2. {
    3.     private void OnTriggerEnter(Collider other)
    4.     {
    5.         if (other.CompareTag("Player"))
    6.         {
    7.  
    8.         }
    9.     }
    10. }
     
  2. Simpso

    Simpso

    Joined:
    Apr 20, 2015
    Posts:
    158
    First you need to create a reference to your text object.
    Then you need an int or a float variable which will hold your number.

    Then within your collider.

    Simply put

    Code (csharp):
    1.  
    2.  
    3.  
    4. Myvalue ++
    5. My text.text = myvalue
    6.  
     
    rudigreig likes this.