- Home /
How do i make a 2D texture Pops up when a player went through the collider?
Yeah, i am super-duper new to unity and i am a student, any help would be very grateful preferably javascript.
So, I wanted to make a message pop up basically when the player pass through the box collider.
I have made the image for the message.
This is currently my code
public var message: Texture2D
private var messagePopup: boolean
function OnCollisionEnter (myCollison : Collision) {
{
}
and i am not even sure if this would work, my guess it wont.. i am so bad at this.. :D
Answer by Zamaroth · Oct 27, 2013 at 11:09 AM
To display a texture on screen, you need to use the GUI.DrawTexture(...) function.
GUI functions also must be placed inside of OnGUI function.
Your code should look like this:
public var message: Texture2D
private var messagePopup: boolean
function OnCollisionEnter (myCollison : Collision)
{
messagePopup = true;
}
function OnGUI()
{
if(messagePopup == true)
{
GUI.DrawTexture(Rect(20,20,100,50), message);
}
}
However if you need to display just a simple string, I recommend you to use GUI.Label function instead:
GUI.Label(Rect(20,20,100,50), "Your message");
You can find more about GUI in unity docs:
Your answer
Follow this Question
Related Questions
Reusable Canvas for enlarging images 2 Answers
Possible to convert UnityEngine.2DTexture to UnityEngine.UI.Image? 1 Answer
Blending two Texture2D 1 Answer
Image isn't displayed on sprite editor windows 0 Answers
Image in label + string..? 1 Answer