Unity 5 - Showing Text on Trigger

Поделиться
HTML-код
  • Опубликовано: 19 дек 2024

Комментарии • 94

  • @adev9224
    @adev9224 4 года назад +6

    Omg you literally saved my life! I was searching for this like 2 or 3 hours. The others are either so hard to understand or the code lines were not suitable for my game. Thank you!

  • @yeanneaudrey
    @yeanneaudrey 2 года назад

    Thank you so much. Being with much of mess with a lot of videos and finally found your video. I just like want to cry when my coding is successful!❤️❤️❤️

  • @carroll6
    @carroll6 4 года назад +1

    Thank you so much. I tried this in my prototype.. Unity 2019.3 worked like a champ.

  • @AndrewChason
    @AndrewChason 4 года назад +1

    just found your channel today, thank you for being. This has inspired me greatly.

  • @semiuodunayoadebayo6299
    @semiuodunayoadebayo6299 Год назад

    Thanks for your help; I referenced you in the presented work

  • @grandmasterskitz748
    @grandmasterskitz748 6 лет назад +4

    Pretty cool tutorial! I kept trying to get the IEnumerator to work for days but wasn't using the Coroutine(string) properly lol
    So luckily I randomly stumbled upon your tutorial! +1 like for saving the day :p

  • @DougyFreshGames
    @DougyFreshGames 5 лет назад +2

    everything works but the text doesn't get destroyed/disappear at the end of the script, not sure whats wrong. it just stays on the screen. Seems the uiobject.SetActive(false) is stalling the coroutine and my debug log isn't coming up.

    • @Xti3012
      @Xti3012 5 лет назад +1

      same! I've tried so many ways to make it disappear and it doesn't. Can someone please help us

    • @DougyFreshGames
      @DougyFreshGames 5 лет назад +5

      @@Xti3012 Hey!, I did a workaround and it works now, try this:
      public GameObject uiText;
      public bool enter = true;
      public bool exit = true;
      public float time = 5; //Seconds to read the text
      void Start()
      {
      uiText.gameObject.SetActive(false);
      }
      void OnTriggerEnter(Collider col)
      {
      if (enter)
      {
      uiText.gameObject.SetActive(true);
      }
      }
      void OnTriggerExit(Collider col)
      {
      if (exit)
      {
      uiText.gameObject.SetActive(false);
      Debug.Log("Its working at this point");
      }
      }
      }

    • @Xti3012
      @Xti3012 5 лет назад +1

      @@DougyFreshGames omg it works!! Thank you so much!! :D

    • @zeroiq4737
      @zeroiq4737 5 лет назад

      @@DougyFreshGames not working...

    • @thespectraprime
      @thespectraprime 2 года назад

      @@DougyFreshGames thanks man

  • @shubhammukherjee2405
    @shubhammukherjee2405 3 года назад

    This is great.... helped me......... This can be used if a person wants to get into a car and showing a drive button...
    PS : works great for webgl builds

  • @shang_psycho7414
    @shang_psycho7414 2 года назад +2

    Here is the script: I added comments as well
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class TriggerText : MonoBehaviour
    {
    public GameObject uiObject;
    void Start() //Make the text invisible at first
    {
    uiObject.SetActive(false);
    }
    void OnTriggerEnter(Collider player) // Once the player enters the trigger, the text will display
    {
    if(player.gameObject.tag == "Player")
    {
    uiObject.SetActive(true);
    StartCoroutine("WaitForSec");
    }
    }
    IEnumerator WaitForSec() // Destroy the text and trigger after five seconds
    {
    yield return new WaitForSeconds(5);
    Destroy(uiObject);
    Destroy(gameObject);
    }
    }

  • @FabiLous09
    @FabiLous09 2 года назад

    it doesn't work 4 me it says, "The variable uiObject of showUI has not been assigned" please help.

  • @seherhocarobotiktv1895
    @seherhocarobotiktv1895 3 года назад

    ı'm making a project and this video helped me thank you very much♥♥♥

  • @lucaslorrimer490
    @lucaslorrimer490 4 года назад +1

    Wont work i have followed the script exactly and added all the tags but it wont activate my text :( please help

    • @Jan-zi2fn
      @Jan-zi2fn 4 года назад

      same here, it has something to do with the player object not technically existing in the given context, i'll try to look for a fix and will inform you if i find one

    • @dylancurry5499
      @dylancurry5499 4 года назад

      It is from 2017 so there might be a few bugs... also me too!

  • @georgerabus9314
    @georgerabus9314 5 лет назад +1

    not working
    here is the code:
    using UnityEngine;
    public class OnCollisionETC : MonoBehaviour
    {
    public GameObject text;
    private void Start()
    {
    text.SetActive(false);
    }
    void OnTriggerEnter2D(Collider2D collision)
    {
    Debug.Log("TRIGGER");
    if(collision.gameObject.tag == "Player")
    {
    text.SetActive(true);
    }
    }
    }
    Any idea?
    The console says it triggers

    • @rimasingh4143
      @rimasingh4143 4 года назад +2

      It says trigger because in Debug.Log("Trigger"). So change it to anything else it should work

  • @СемёнТатаринов-е2у
    @СемёнТатаринов-е2у 2 года назад

    Thank You very much bro I'm your new subscriber

  • @amjadmohsin7
    @amjadmohsin7 2 года назад

    How to see the text again if i already saw the text and then i want to see it again, what should I write in script? thanks in advance

  • @dawid2764
    @dawid2764 6 лет назад +5

    The best tutorial of this, thank you man!

  • @RodrigoMatela
    @RodrigoMatela 4 года назад

    Hi, how did you do that player rotation following the camera so smooth? Thanks

  • @jordantower3934
    @jordantower3934 6 лет назад +1

    How do you include multiple text triggers within one scene?

  • @wehh1
    @wehh1 7 лет назад +3

    What shader are you using for the cartoon and outline effect

    • @2kmixedit
      @2kmixedit  7 лет назад +1

      I think it's called TSF shader, it's free on the asset store.

  • @benjaminjanowitz7328
    @benjaminjanowitz7328 6 лет назад +3

    hi, what about showing different texts with different triggers?+

    • @FSAirsoftUK
      @FSAirsoftUK 5 лет назад

      add same script to the thing u want to trigger but change the text u want to show/hide

  • @andrewballantyne1696
    @andrewballantyne1696 4 года назад

    UnassignedReferenceException: The variable uiObject of textShow has not been assigned.
    You probably need to assign the uiObject variable of the textShow script in the inspector.
    textShow.Start () (at Assets/Scripts/textShow.cs:10)

  • @dylancurry5499
    @dylancurry5499 4 года назад +1

    Can someone help? I get the warning that says: OnTriggerEnter is declared but never used, here is my code
    {
    public GameObject uiObject;
    void Start()
    {
    uiObject.SetActive(false);
    void OnTriggerEnter (Collider Player)
    {
    if (Player.gameObject.tag == "Player")
    {
    uiObject.SetActive(true);
    StartCoroutine("WaitForSec");
    }
    }
    }
    IEnumerator WaitForSec()
    {
    yield return new WaitForSeconds(10);
    Destroy(uiObject);
    Destroy(gameObject);
    }
    }

  • @АртемийРязанов-н5ъ
    @АртемийРязанов-н5ъ 2 года назад

    this video saved me really thanks!!

  • @FSAirsoftUK
    @FSAirsoftUK 5 лет назад

    hi, so ive adjusted the code differently but im not sure why its not working can u pls help?
    public class Interact : MonoBehaviour
    {
    public GameObject interactive;
    void Start()
    {
    interactive.SetActive(false);
    }
    void OnTriggerEnter (Collider player)
    {
    if (player.gameObject.tag == "Player")
    {
    interactive.SetActive(true);
    }
    }
    void OnTriggerExit (Collider player)
    {
    if (player.gameObject.tag == "Player")
    {
    interactive.SetActive(false);
    }
    }
    }

  • @protieusgamerz2494
    @protieusgamerz2494 7 лет назад +1

    When r u going to upgrade to unity 2017.10?
    I'm wondering how can you make it so like in "the lady day on earth" you can goto different regions and pick up wood, stone and when you kill animals get their meat and leather to make things. Could you make a tutorial and script showing that thanks soo much

    • @2kmixedit
      @2kmixedit  7 лет назад

      I've already made videos that have that kind of functionality or at least similar to it, check my channel, the adventure game tutorial series and other videos on collecting items etc. A lot of them have similar things to the gameplay you need.

  • @XeroSHWANG
    @XeroSHWANG 3 года назад

    dosent work with text mesh which is what im trying to do bc text mesh is crisper

  • @josemiranda7386
    @josemiranda7386 5 лет назад +1

    You are the best human in the world

  • @ylyasyylkybayev689
    @ylyasyylkybayev689 4 года назад

    Can you give me the link for this project with models?

  • @spo2957
    @spo2957 5 лет назад +1

    if you are trying to make this into an item text pickup then can try something like this
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class PickUp : MonoBehaviour
    {
    Animator anim;
    Inventory invScript;
    public bool money;
    public int moneyAmount;
    Currency moneyScript;
    public bool item;
    public GameObject itemIcon;
    public GameObject PickUpText;
    bool pickedUp = false;
    // Use this for initialization
    void Start()
    {
    anim = GameObject.FindWithTag("Player").GetComponent();
    moneyScript = GameObject.FindWithTag("GameController").GetComponent();
    invScript = GameObject.FindWithTag("GameController").GetComponent();
    }
    // Update is called once per frame
    void OnTriggerStay(Collider player)
    {
    if (player.tag == "Player")
    {
    if (Input.GetKeyDown(KeyCode.E) && !pickedUp)
    {
    pickedUp = true;
    StartCoroutine("PlayAnim");
    }
    }
    }
    private void OnTriggerEnter(Collider player)
    {
    if (player.tag == "Player")
    {
    PickUpText.SetActive(true);
    }
    }
    private void OnTriggerExit(Collider player)
    {
    if (player.tag == "Player")
    {
    PickUpText.SetActive(false);
    }
    }
    IEnumerator PlayAnim()
    {
    anim.SetTrigger("pickup");
    yield return new WaitForSeconds(1);
    PickUpText.SetActive(false);
    if (money)
    {
    moneyScript.gold += moneyAmount;
    Destroy(gameObject);
    }
    else if (item)
    {
    GameObject i = Instantiate(itemIcon);
    i.transform.SetParent(invScript.invTab.transform);
    Destroy(gameObject);
    }
    }
    }

  • @desmondsstudio3487
    @desmondsstudio3487 7 лет назад

    Do I need a lesson on reading the notes.
    What would it be if you pressed it on E, you could take it.
    And when you read it was impossible to move!

    • @2kmixedit
      @2kmixedit  7 лет назад

      Sure I'll do something soon.

  • @amantepam
    @amantepam 6 лет назад

    Hey Guys
    I was wondering if you could make it a public float, so you could adjust the time, but I'm not quite sure how pls help me. thanks

    • @2kmixedit
      @2kmixedit  6 лет назад

      Yes, sorry the late reply, just make a public float, call it whatever you want and instead of the number at the Destroy function enter the name of the float.

  • @LiminalDreams91
    @LiminalDreams91 6 лет назад +2

    Will this script work in a 2D environment? I'm trying to use the Box Collider 2D component but nothing is happening when I go into the box and the script is 1:1

    • @pewn3215
      @pewn3215 5 лет назад

      Same problem

    • @pewn3215
      @pewn3215 5 лет назад +4

      I found out a solution:
      Rename OnTriggerCollider to OnTriggerCollider2D and Collider to Collider2D

  • @bottleofgreed4415
    @bottleofgreed4415 Год назад

    where can we find this naruto unity setup?

    • @2kmixedit
      @2kmixedit  Год назад +1

      Hey, it's a combination of free assets I found online while making these videos. I just set it up for the purpose of these tutorials so honestly I'm unsure. Message me on Instagram @2kmixed.it I'll send you a link to one of the sites where I got the environment and character models because I can't post links here.

  • @creed8196
    @creed8196 4 года назад

    I typed exactly what you have done and come up with an error unfortunately, Im going to rewatch incase I missed something though

  • @mmazuk1958
    @mmazuk1958 3 года назад

    Thanks for tutorial!

  • @sinderymonk6718
    @sinderymonk6718 2 года назад

    Very useful thank you very much!

  • @novariation3
    @novariation3 2 года назад

    Dude THANK YOU SOOOOOO MUCH

  • @Cyn1calll
    @Cyn1calll 7 лет назад +5

    may i can download the map?? i making a fansmade game :-)

  • @david25201
    @david25201 4 года назад

    Thank you this really helped me!

  • @markclintsman9872
    @markclintsman9872 2 года назад

    Just wanted to tell you, this really is a great tutorial. It's to the point and really cut down on things for me. I wanted to ask you is there a way to grab the UI Text and combine it with a variable to give it a name of the object you are interacting with? For example "Press E to interact with + {GameObjectName}" this would look something like if you set GameObjectName variable to say "Cat". Than it would look like this when you on trigger "Press E to interact with Cat". Thanks for the tutorial!

  • @damsan7777
    @damsan7777 3 года назад

    Great video, little old, but i get this errors. Compiler Error CS0229, uiObject.SetActive(false); uiObject is not the right name, something like that. Thank you

  • @amandamiller2198
    @amandamiller2198 Год назад

    does this work for vr too

    • @amandamiller2198
      @amandamiller2198 Год назад

      also how do i make the game object invisible that im going to hit

  • @Mynameiskaiu
    @Mynameiskaiu 6 лет назад +1

    Please help!
    My Text just isn't responding to the trigger. It doesn't get ticked/appear when I hit the mesh renderer of my trigger but there is no error displayed either. Any ideas what might be wrong?

    • @grandmasterskitz748
      @grandmasterskitz748 6 лет назад

      Set a Debug.Log() inside of your OnTriggerEnter*() function to see if your Player's collider is interacting with the cube's collider. If you're not responding then perhaps you've failed to initialize your tag "Player". Check the script inside unity and see if your player is attached and/or if the script is attached to the cube. Sometimes unity doesn't let me initialize my game objects until the script is attached to something.

  • @kaamosVendetta
    @kaamosVendetta 4 года назад

    Hi.
    how I can show an image, like interrogation or exclamation sing, up to the character head when it enter the collider? one part is easy, instead of text, i select the image on canvas, but the other part, show it up to the character head?
    Thanks for the tutorial.

  • @williammayfield7465
    @williammayfield7465 6 лет назад

    Great video! Thanks

  • @cgiink
    @cgiink 3 года назад

    Nice tutorial! Thank you. If is not too hard, how do I achieve if I want the message to disappears when the player walks away the area and shows up again when the player walks back to the same area? Please

  • @prasadnimse4360
    @prasadnimse4360 5 лет назад

    good tutorial. thank you,

  • @kal7383
    @kal7383 4 года назад +1

    tysm! ur a lifesaver!

  • @kolilpop
    @kolilpop 4 года назад +1

    nice naruto game

  • @creatorlater5942
    @creatorlater5942 7 лет назад

    Great video as always!

  • @fiftyseven.fiftyeight
    @fiftyseven.fiftyeight 2 года назад

    God bless you 🙏

  • @tejasbele1456
    @tejasbele1456 3 года назад

    Thank you so much

  • @RobertGercia
    @RobertGercia 4 года назад

    Cool stuff!!

  • @457Deniz457
    @457Deniz457 6 лет назад

    where do u got this awesome assets from? :O
    i love naruto :D

  • @Willskull
    @Willskull 2 года назад

    Thanks!!

  • @babyyodaslightsaber6882
    @babyyodaslightsaber6882 2 года назад

    For me it Says ; expected

  • @sanjuktabhattacharyab19ee02
    @sanjuktabhattacharyab19ee02 4 года назад

    It's not working :(

  • @dronehq2816
    @dronehq2816 3 года назад

    Thanks man

  • @vlado3915
    @vlado3915 2 года назад

    thanks...

  • @KLB97HD
    @KLB97HD 6 лет назад

    Awesome !!!!!! thanks

  • @asirsakin5562
    @asirsakin5562 6 лет назад

    thanks man love

  • @holymother6657
    @holymother6657 6 лет назад

    thanks

  • @irl962
    @irl962 4 года назад

    or you could add a OnTriggerExit Function and it would appear and dissapear as u either enter or exit the collider xDDD

    • @shaybizzle
      @shaybizzle 3 года назад

      did you end up finding a solution for this? because this is exactly what im looking for!

  • @pannarooksana6731
    @pannarooksana6731 6 лет назад +2

    KAKASHI!!

  • @Dhairya_Mistry
    @Dhairya_Mistry 4 года назад

    i ju\st subbed very\ h\elp\fu\l thans dude!

  • @pinkmelon4350
    @pinkmelon4350 4 года назад

    ok next /

  • @mikethegamedev
    @mikethegamedev 4 года назад

    naruto game

  • @gameboyatron1405
    @gameboyatron1405 4 года назад

    You sound dead inside through this tutorial, the information was good but you sound very unenthused