Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TSX_Crytek · Jan 09, 2014 at 02:22 AM · c#collision

Displaying text on trigger enter

Hello everyone, I have a question for you all today. I have been trying to display some text telling a player to turn back or be killed so that they don't fall off the map, but I am having some trouble actually displaying it on the screen. My code so far is as follows:

 using UnityEngine;
 using System.Collections;

 public class Boundaries : MonoBehaviour 
 {
     //Declaring variables
     bool crossedBoundary;
     void OnTriggerEnter(Collider other) 
 {
     //Telling game to actiavte boolean
     if(other.gameObject.tag == "Player") 
     {
         crossedBoundary = true;
     }
 }
 void OnGUI () 
 {
     //If the boolean is active, display the text
     if (crossedBoundary == true) 
     {
         GUI.Label(Rect(200, 100, 0, 0), "Turn back or die!");
     }
 }
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Invertex · Jan 09, 2014 at 04:05 AM 0
Share

Another tip while we're here, you only need to write the name of the bool, to check if true. Like this:

 if (crossedBoundary)
 {
 dostuff();
 }

And just use an ! if you want it to check if not true. (!crossedBoundary).

avatar image TSX_Crytek · Jan 10, 2014 at 02:55 AM 0
Share

Thanks, now I know some more about C# :)

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Invertex · Jan 09, 2014 at 02:40 AM

Well, one clear issue is that you forgot to put "new" before the "Rect" call. It should be:

  GUI.Label(new Rect(200, 100, 0, 0), "Turn back or die!");
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sericet1 · Jan 09, 2014 at 03:15 AM 1
Share

Also, make sure you have the player object tagged as Player.

avatar image TSX_Crytek · Jan 10, 2014 at 02:53 AM 0
Share

Thanks, I'll try this as soon as I have time. While you guys are still here, what would you recommend I do for the countdown timer until the Player actually dies? I've heard something about coroutines, but I don't really understand what they are. Again, thanks for your help (can't believe one word caused me to stay up for 2 hours trying to figure out what was wrong with my script!)

avatar image Invertex · Jan 10, 2014 at 03:27 AM 0
Share

Coroutines run separate from the Update function, and in them, you can declare Wait times, such as "`yield return new WaitForSeconds(10.0f);`". You'd set up a coroutine by making a new method in your script, starting with "IEnumerator" then "name you want" and () encapsulation. So:

 IEnumerator playerWait(){
 do stuff;
 yield return new WaitForSeconds(10.0f);
 do more stuff;
 }

It has a lot of uses. I'd suggest reading up more on them :)

http://unitygems.com/coroutines/

(Oh, and you'd initiate the Coroutine from somewhere else in your script, when you wanted to, with StartCoroutine(playerWait()); Assu$$anonymous$$g your coroutine was named "playerWait".)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Need help with scripting bug fix. pleease 0 Answers

C# GameObject is not detecting collision with Character Controller 2 Answers

Collision between capsule and sphere colliders does not work 1 Answer

C# Plane Collision Detection 1 Answer

OnCollisionStay only detects collisions after a secondary collision 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges