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 paverson · Jul 17, 2012 at 07:28 AM · triggertextguitextnoob

Trigger Script Not Firing

I'm going through the book "Creating Games w/ Unity & Maya" by Adam Watkins. I've been stuck on the same section for 2 hours, and I can't figure out what is going wrong! The final trigger (LoadLevel) works, but the guiText triggers don't. I've pasted both JScripts below...

     private var guiTextObject : GameObject;
 function Awake(){
  guiTextObject = GameObject.Find("GUITextHints");
 }
 function OnTriggerEnter (other:Collider){ 
  if (name == "Trigger-FindDoorHint"){ 
  guiTextObject.GetComponent(EntryWayGUITextScript).FindDoorHint();
 }
  if (name == "Trigger-WaterHint"){
  guiTextObject.GetComponent(EntryWayGUITextScript).StayOutOfWaterHint( );
  }
  if (name == "Trigger-EMPHint"){
  guiTextObject.GetComponent(EntryWayGUITextScript).TryEMPHint( );
  }
  if (name == "Trigger-HallwayPortal"){
  Application.LoadLevel ("Scene-Hallway");
  }
 }

and also

       function FindDoorHint (){
  guiText.enabled = true;
  guiText.text = "Find the secure entrance to the base.";
  yield WaitForSeconds (3);
  guiText.enabled = false;
 }
 
 function StayOutOfWaterHint (){
  guiText.enabled = true;
  guiText.text = "Stay out of the water! At this temperature, it's lethal.";
  yield WaitForSeconds (5);
  guiText.enabled = false;
 }
 
 function TryEMPHint (){
  guiText.enabled = true;
  guiText.text = "Try using EMP to disable exterior secuirty system.";
  yield WaitForSeconds (5);
  guiText.enabled = false;
 }

HELP!

Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by asafsitner · Jul 17, 2012 at 08:02 AM

Wait, so the script with the OnTriggerEnter method is located on the triggers?

Otherwise if it's part of the player object then you're comparing the player's name (`name` with lowercase returns the name this script is attached to) against what should be the triggers's name.

If it's on the player try it with other.name instead to compare the trigger's name.

if it's on the triggers themselves... shouldn't you know what the trigger's name is?

In that case you can just remove that long list of ifs and just do what that specific trigger is meant to do. Also, double-check your names.

Comment
Add comment · 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
0

Answer by paverson · Jul 17, 2012 at 02:42 PM

thanks for the quick reply, asafsitner.

the script is indeed attached to the trigger (a big invisible cube that the FPSController goes through). the trigger's name is "Trigger-FindDoorHint" (hence the name == "Trigger-FindDoorHint").

I've tripled - no - quintuple checked my names, and even found a digital copy of the book online and copied and pasted the code! I'm about ready to give up, as I simply can't figure out what the heck is wrong (especially since the .LoadLevel command works). I've attached screengrabs, to help you visualize what I'm trying to do.

alt text

alt text

Comment
Add comment · 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
0

Answer by Meltdown · Jul 17, 2012 at 02:48 PM

Change

 if (name == "Trigger-FindDoorHint"){ 
  guiTextObject.GetComponent(EntryWayGUITextScript).FindDoorHint();
 }

to

 if (other.name == "Trigger-FindDoorHint"){ 
      guiTextObject.GetComponent(EntryWayGUITextScript).FindDoorHint();
     }

So you change the name check to other.name Do that for each one..

Comment
Add comment · Show 14 · 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 paverson · Jul 17, 2012 at 03:21 PM 0
Share

I tried that, and unfortunately no dice (again, the name isn't the issue, as it is firing on the last "Trigger-HallwayPortal" Trigger. I simply can't figure this damn thing out.

avatar image Meltdown · Jul 17, 2012 at 03:33 PM 0
Share

Have you tried using Debug.Log(other.name); or Debug.Log(name); in OnTriggerEnter to see what is actually happening and what trigger your character is colliding with?

I'd suggest also addding OnTriggerEnter to your character controller and Debug.Log(other.name); on that to see if your character is actually colliding with the trigger.

avatar image paverson · Jul 17, 2012 at 03:58 PM 0
Share

$$anonymous$$eltdown,

Thanks for the quick reply. I'm such a nOOb, that I don't even know what you're talking about (concerning Debug.Log(name). I'll try and search around for how to execute that and see if it works.

thanks.

avatar image Meltdown · Jul 17, 2012 at 04:00 PM 0
Share

In Unity press CTRL + SHIFT + C to open the Console window. You use this window to see errors and debug information. Each time OnTriggerEnter is called, you can use Debug.Log(variable); to see what the value is for any variable or string.. its very useful for working out problems.

avatar image paverson · Jul 17, 2012 at 04:19 PM 0
Share

I might be making some progress w/ this, thanks to you. I'm getting this feedback from the Console: $$anonymous$$issingComponentException: There is no 'GUIText' attached to the "Trigger-FindDoorHint" game object, but a script is trying to access it. You probably need to add a GUIText to the game object "Trigger-FindDoorHint". Or your script needs to check if the component is attached before using it.

The problem is that the GUIText IS attached to the game object (well, the two scripts from above are attached to it, which is what I'm assu$$anonymous$$g Unity is talking about). This is such a stumper, and I'm SURE it is some simple step I missed (even though I've gone through the book's instructions 3 times now!)

Show more comments
avatar image
0

Answer by paverson · Jul 18, 2012 at 07:43 AM

Well, I guess it pays to be persistent (and a bit creative?). I figured - why make this so complicated with two scripts, and pare it down to one? I know the author was trying to show an efficient way that scripting could be applied across the level, but it just wasn't working for me. So (thanks to a lot of advice/help from you guys), I FINALLY figured it out. Now the different text prompts come up when I walk the FPSController through the various "invisible boxes". Well, that's roughly 5 hours down the tube. I have a LOT of appreciation/respect for those of you that know what you're doing when you're writing and reading this stuff! Thanks again! See below!

 var  guiTextDoor : GameObject; 
 var guiTextWater : GameObject;
 var guiTextEMP : GameObject;
 
 function Awake (){
  guiTextDoor = GameObject.Find("GUITextHints"); 
  guiTextWater = GameObject.Find("GUITextHints");
  guiTextEMP = GameObject.Find("GUITextHints");
 }
 
 function OnTriggerEnter (other:Collider){ 
  if (name == "Trigger-FindDoorHint"){
  guiTextDoor.guiText.enabled = true;
  guiTextDoor.guiText.text = "Find the secure entrance to the base.";
  yield WaitForSeconds (3);
  guiTextDoor.guiText.enabled = false;
  }
   if (name == "Trigger-WaterHint"){
  guiTextWater.guiText.enabled = true;
  guiTextWater.guiText.text = "Stay out of the water! At this temperature, it's lethal.";
  yield WaitForSeconds (3);
  guiTextWater.guiText.enabled = false; 
  }
  if (name == "Trigger-EMPHint"){
  guiTextEMP.guiText.enabled = true;
  guiTextEMP.guiText.text = "Try using EMP to disable exterior secuirty system.";
  yield WaitForSeconds (3);
  guiTextEMP.guiText.enabled = false; 
  }
  if (name == "Trigger-HallwayPortal"){
  Application.LoadLevel ("Scene-Hallway");
  }
 } 
Comment
Add comment · 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

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

8 People are following this question.

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

Related Questions

GUIText only appearing in Unity Simlutor, but not actual iPad..why? 0 Answers

Making my Text fade in on a trigger 2 Answers

GUIText not working properly with a timer. 1 Answer

How would I make the text bigger on this script? 1 Answer

Scrolling Text 1 Answer


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