Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Trigger Event on Text

Discussion in 'Scripting' started by Corrothon, Aug 16, 2020.

  1. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    I'm making a horror game and I want text to appear when you walk on an invisible cube.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,947
    Use a trigger BoxCollider and show the text in OnTriggerEnter
     
    Kurt-Dekker likes this.
  3. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    I'm a bit confused I want TMP Text to show up here's my script (remember Im not a pro on C# yet lol):

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class HuhScript : MonoBehaviour
    {



    // Start is called before the first frame update
    void Start()
    {


    // Update is called once per frame
    void Update()
    {

    }

    void OnTriggerEnter(Collider other)
    {
    Debug.Log(other.name + " Has Entered!");
    }

    void OnTriggerExit(Collider other)
    {
    Debug.Log(other.name + " Has Exited!");
    }




    }
    }

    Script is from a tutorial that I followed along with
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,947
    You put all of your other functions inside of the Start() function. You need to move them out of the Start function, or Unity will not call them. If you use standard code indentation you will notice a problem like this faster.
     
  5. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    What do you mean? (Sorry I am a bit tired)
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,947
    "{" marks the beginning of a function.

    "}" marks the end of a function.

    Your Start function starts here:
    Code (CSharp):
    1. void Start()
    2. {
    Then it doesn't end until nearly the end of the file. That means all of your other functions are inside of it. Take them out.
     
    Corrothon likes this.
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,947
  8. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
  9. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,947
    Well now you're making progress!