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 inf3ctedsystem · Feb 23, 2014 at 12:15 AM · not-workingunresponsive

Code isn't running through

So I'm trying to make a Ahem Potato say something when the Player enters the Trigger and Left clicks on the Potato Game object (all of this is 2D). The Potato will ask a question and depending on the answer from the player the Potato will respond appropriately, and after the player answers the question the Potato will not ask any more questions as it marks as has talked to.

BUT

I have run into a problem the Potato won't talk when clicked on. The Potato game object is 0 on the Z axis and is set to trigger. I'm using C# and for the Life of me I cannot find out why. If you take time to fix this please explain what was wrong as I like to learn from mistakes.

 using UnityEngine;
 using System.Collections;
 
 public class ProtatoTalk : MonoBehaviour {
     public string [] answerButton;
     public string [] Questions; 
     bool DisplayDialog = false; 
     bool HasTalkedTo = false; 
 
     void onGUI()
     {
         GUILayout.BeginArea (new Rect (1, 1, 400, 400)); 
         if (DisplayDialog && !HasTalkedTo) 
     {
 
             GUILayout.Label(Questions[0]);
             if(GUILayout.Button (answerButton[0]))
             {
                 GUILayout.Label (Questions[1]);
                 HasTalkedTo = true; 
             }
 
             if(GUILayout.Button (answerButton[1]))
             {
                 GUILayout.Label (Questions[2]);
                 HasTalkedTo = true;
             }
 
     }
         GUILayout.Label (Questions[3]); 
         GUILayout.EndArea(); 
     }
     
         void OnTriggerEnter()
     {
         if(Input.GetMouseButtonDown(0))
             DisplayDialog = true; 
     }
 
     
         void OnTriggerExit()
     {
         DisplayDialog = false;
     }
 }
 

 
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

1 Reply

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

Answer by Bunnybomb7670 · Feb 23, 2014 at 12:20 AM

I think the issue is that you are calling you're code from OnTriggerEnter, if you think about it, that function is only called for one frame, you are expecting the player to collide with AND click in the same frame to call the dialog? I think you need to change it to OnTriggerStay because that is called every frame that the object stays with a collision.

Comment
Add comment · Show 1 · 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 Bunnybomb7670 · Feb 23, 2014 at 12:42 AM 0
Share

$$anonymous$$ake sure there is a rigidbody attached to one of them otherwise it wont call the trigger.

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

20 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

Related Questions

UNITY Scripting - True and False not working! 3 Answers

Putting objects inside an empty GameObject changes the original position. 1 Answer

Custom Editor Window not opening after layout crash 1 Answer

NPC AI Unresponsive after spotting player once 2 Answers

Do I need an Apple developer account for Mac for my app to run properly? 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