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 OctoSloths · Nov 28, 2014 at 08:38 PM · c#gui-buttondialogueontriggerenter2d

Dialogue OnTriggerEnter2D not working

So I've imported the asset "Dialoguer" and I'm trying to make it so that a gui button will appear to begin the conversation once I enter a trigger in a 2D game but it's not working to far. I have this script which I put on a 2D box collider:

 using UnityEngine;
 using System.Collections;
 
 public class DialoguerExampleStart : MonoBehaviour {
 
     void Awake(){
         // You must initialize Dialoguer before using it!
         Dialoguer.Initialize();
     }
     void OnTriggerEnter2D (other: Collider2D){
     void OnGUI(){
         if(GUI.Button (new Rect(10,10,100,30), "Start!")){
 
             Dialoguer.StartDialogue(3);
 
 }
 }
     }
 }

And I'm not sure how to edit it so that it works that way. I know this is completely wrong but I'm very new to coding so I'm not sure how it's wrong or how to fix it. :( Any help would be much appreciated.

I get the errors: Assets/DialoguerExamples/_ExampleScene/Classes/DialoguerExampleStart.cs(18,9): error CS8025: Parsing error

Assets/DialoguerExamples/_ExampleScene/Classes/DialoguerExampleStart.cs(11,19): error CS1525: Unexpected symbol (', expecting )', ,', ;', [', or ='

Assets/DialoguerExamples/_ExampleScene/Classes/DialoguerExampleStart.cs(11,18): error CS1547: Keyword `void' cannot be used in this context

Assets/DialoguerExamples/_ExampleScene/Classes/DialoguerExampleStart.cs(10,32): error CS1041: Identifier expected

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

2 Replies

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

Answer by OctoSloths · Nov 29, 2014 at 03:16 AM

I figured it out! Here is the code in case anyone ends up needing it:

 using UnityEngine;
 using System.Collections;
 
 public class DialoguerExampleStart : MonoBehaviour {
 private bool bShowGUI = false;
     void Awake(){
         // You must initialize Dialoguer before using it!
         Dialoguer.Initialize();
     }
     void OnTriggerEnter2D (Collider2D other){
         bShowGUI = true;
     }
     void OnTriggerExit2D (Collider2D other) {
                 bShowGUI = false;
         }
     void OnGUI(){
                 if (bShowGUI) {
                         if (GUI.Button (new Rect (10, 10, 100, 30), "Investigate")) {
 
                                 Dialoguer.StartDialogue (0);
 
                         }
                 }
         }    
 }
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 spiceboy9994 · Nov 28, 2014 at 09:40 PM

Well the code is not correct from my point of view. Why do you have OnGUI Method within the OnTriggerEnter2D... separated those methods and you'll be fine

 void OnTriggerEnter2D (other: Collider2D){
 }
 void OnGUI(){
    if(GUI.Button (new Rect(10,10,100,30), "Start!")){ 
       Dialoguer.StartDialogue(3);
    }
  
  }
 

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 OctoSloths · Nov 28, 2014 at 09:47 PM 0
Share

Okay this allows the script to run but the GUIButton is visible without entering the trigger. I'm trying to make it so the button only appears after the player has entered a 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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make a GUI Button shrink when pressed 4 Answers

Run script when level begins? 1 Answer

Using a GUI button to stop a gameobject movement 3 Answers

Button Script issue, works in game mode not in build and run 1 Answer

calling buttons in triggers 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