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!
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!❤️❤️❤️
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
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 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"); } } }
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
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); } }
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
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
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)
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); } }
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); } } }
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
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.
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); } } }
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.
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
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.
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!
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
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?
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.
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.
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
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!
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!❤️❤️❤️
Thank you so much. I tried this in my prototype.. Unity 2019.3 worked like a champ.
just found your channel today, thank you for being. This has inspired me greatly.
Thanks for your help; I referenced you in the presented work
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
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.
same! I've tried so many ways to make it disappear and it doesn't. Can someone please help us
@@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");
}
}
}
@@DougyFreshGames omg it works!! Thank you so much!! :D
@@DougyFreshGames not working...
@@DougyFreshGames thanks man
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
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);
}
}
Ty man
@@SlaySlay-s7h yw
it doesn't work 4 me it says, "The variable uiObject of showUI has not been assigned" please help.
ı'm making a project and this video helped me thank you very much♥♥♥
Wont work i have followed the script exactly and added all the tags but it wont activate my text :( please help
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
It is from 2017 so there might be a few bugs... also me too!
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
It says trigger because in Debug.Log("Trigger"). So change it to anything else it should work
Thank You very much bro I'm your new subscriber
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
The best tutorial of this, thank you man!
Hi, how did you do that player rotation following the camera so smooth? Thanks
How do you include multiple text triggers within one scene?
What shader are you using for the cartoon and outline effect
I think it's called TSF shader, it's free on the asset store.
hi, what about showing different texts with different triggers?+
add same script to the thing u want to trigger but change the text u want to show/hide
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)
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);
}
}
this video saved me really thanks!!
Cheers mate!
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);
}
}
}
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
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.
dosent work with text mesh which is what im trying to do bc text mesh is crisper
You are the best human in the world
Can you give me the link for this project with models?
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);
}
}
}
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!
Sure I'll do something soon.
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
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.
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
Same problem
I found out a solution:
Rename OnTriggerCollider to OnTriggerCollider2D and Collider to Collider2D
where can we find this naruto unity setup?
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.
I typed exactly what you have done and come up with an error unfortunately, Im going to rewatch incase I missed something though
Thanks for tutorial!
Very useful thank you very much!
Dude THANK YOU SOOOOOO MUCH
may i can download the map?? i making a fansmade game :-)
Thank you this really helped me!
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!
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
does this work for vr too
also how do i make the game object invisible that im going to hit
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?
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.
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.
Great video! Thanks
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
good tutorial. thank you,
tysm! ur a lifesaver!
nice naruto game
Great video as always!
Thanks man :)
God bless you 🙏
Thank you so much
Cool stuff!!
where do u got this awesome assets from? :O
i love naruto :D
Thanks!!
For me it Says ; expected
It's not working :(
Thanks man
thanks...
Awesome !!!!!! thanks
thanks man love
thanks
or you could add a OnTriggerExit Function and it would appear and dissapear as u either enter or exit the collider xDDD
did you end up finding a solution for this? because this is exactly what im looking for!
KAKASHI!!
SASUKE!!!
NARUTO!!
i ju\st subbed very\ h\elp\fu\l thans dude!
ok next /
naruto game
You sound dead inside through this tutorial, the information was good but you sound very unenthused