Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Forbidden_Duck · Jan 15, 2017 at 07:57 AM · unity 5scripting problemuiscript.beginner

Scripts Interfering With Each Other

Hi.

I am just learning Unity so I decided to make a Pong game, I am really really close to finishing it, when I game across something weird

I have 2 scripts, 1 of them Starts the game (I have a Main Menu), the other one Exits. When I assign them to their correct buttons for some reason when I open the .exe file when I click Start it closes the application and when I remove the Exit button altogether the Start button works fine

Comment
Add comment · Show 3
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 UnityCoach · Jan 15, 2017 at 11:04 AM 0
Share

Can you share your code? It would help.

avatar image Forbidden_Duck UnityCoach · Jan 15, 2017 at 11:52 AM 0
Share

Yep Here

Start Button: private bool startedLoad;

 void Update()
 {
     if (Input.Get$$anonymous$$ouseButtonDown(0))
         if (!startedLoad)
         {
             Scene$$anonymous$$anager.LoadScene("scene_test_trail1");
             startedLoad = true;
         }
 }

}

Exit Button: private void Update() { if (Input.Get$$anonymous$$ouseButtonDown(0)) { Application.Quit(); } } }

I also found out that if you click in the Canvas (Which for some reason it is the camera view) it does ever just the Start or Exit script. When I look in Canvas and the $$anonymous$$ain Camera none of the scripts are connected

avatar image ownerfate Forbidden_Duck · Jan 15, 2017 at 12:36 PM 0
Share

you could do this, use the same script for both as you're doing, but assign the buttons to do what they need to do.

i program in Js : code isn't formatted.

e.g. if(isExitButton == true){ //quit the game. }

if(isPlayButton == true){ // start the game }

1 Reply

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

Answer by UnityCoach · Jan 15, 2017 at 04:02 PM

I see, you're using UI Buttons within a Canvas, right?

If so, you can put all your UI functions in one script, like UI Manager, then add the component to an empty game object and assign them to the buttons onClick events in the editor.

 public class UIManager : MonoBehaviour
 {
     public bool startedLoad;
 
     public void StartGame ()
     {
         SceneManager.LoadScene ("scene_test_trail1");
         startedLoad = true;
     }
 
     public void Quit ()
     {
         Application.Quit ();
     }
 }
Comment
Add comment · Show 4 · 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 Forbidden_Duck · Jan 15, 2017 at 11:36 PM 0
Share

I am new to Unity and I have like zero to know idea what you mean. I understand to add them both to one script then what do I do?

avatar image Forbidden_Duck · Jan 15, 2017 at 11:43 PM 0
Share

Ok, I got the GameObject to do On-Click events. I am trying to find out why the Buttons aren't doing anything

avatar image Forbidden_Duck · Jan 15, 2017 at 11:46 PM 0
Share

Ok, thanks! It is working just fine :)

avatar image UnityCoach Forbidden_Duck · Jan 16, 2017 at 10:47 AM 0
Share

There's like 3 layers of UI implementations in Unity now, so it may be a bit confusing if you look at older tutorials. But that is the way to go since Unity 4.6 with the new UI stuff. Glad you got it working.

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

173 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

How to reference script in unity (C#) ? 0 Answers

Image UI not enabling C# SOLVED 1 Answer

How to stop movement script on void start and resume after. 0 Answers

Is there a way I can make one script for all my buttons in my game? 1 Answer

space shooter tutorial issue "Ending the game" unity 2018.2 b 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