• 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
Question by ElectricFountain · Apr 15, 2013 at 02:23 AM · buttonfpsbuttonscontrol

How to get exact button input

For some reason, when I go to click on the multiplayer buttin on the screen, it always loads t$$anonymous$$s script no matter where I click on the screen. i have similar scripts on the same screen for different buttons like settings and so on. Could you help me with t$$anonymous$$s script so that when I go to click on t$$anonymous$$s, it loads only t$$anonymous$$s and when I click on other buttons, it loads only those buttons. In other words, make the GetMouseDown part load an exact coord on the screen.

Sorry if I was not clear with my words...

pragma strict

 function Update () {
     
     if(Input.GetMouseButtonDown(0)){
          Application.LoadLevel("LoadingCampaign");
         }
 }
 
Comment

People who like this

0 Show 0
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

Answer by godwinwong · Apr 24, 2013 at 08:36 AM

Hi, You might want to consider using GUI.Button for t$$anonymous$$s,

     function OnGUI() {
         GUI.Button(Rect(coordinateX, coordinateY, width, height), 
                 "YourButtonText") {
             Application.LoadLevel("LoadingCampaign");
         }
     }

You can create more buttons to load the other scene that you have in the project. Hope t$$anonymous$$s helps.

Comment
AlvinHerawan

People who like this

1 Show 0 · 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

Answer by ahaykal · Apr 24, 2013 at 06:37 AM

Input.GetMouseButton

**static function GetMouseButton (button : int) : boolean

Description Returns whether the given mouse button is held down.**

As you see it is used to detect mouse input w$$anonymous$$ch is not what you want.

You could either use function OnMouseDown() on each button,

Or you can find the position by sending a raycast.

T$$anonymous$$s has been asked a lot from before so try searc$$anonymous$$ng before asking :)

Comment
moghes

People who like this

1 Show 0 · 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

Answer by deltamish · Apr 24, 2013 at 06:39 AM

Hi you can ac$$anonymous$$eve the same effect using GUI Button or GUI Texture here is an script that works using GUI Button (if you want script that works with GUI Texture please do leave a comment)

 var LevelName:String = "LoadingCampaign";//your Level name goes here 
 
 function OnGUI(){//On GUI works same as Update but for GUI's
     GUI.Box(Rect(10,10,100,400),"Menu");//create a box with name Menu
     if(GUI.Button(Rect(20,70,80,20),"Start"))//create a button with name Start and if its clicked continue executing 
     {
         Application.LoadLevel(LevelName);
     }
 }
Comment

People who like this

0 Show 0 · 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

Answer by HunterKrech · Apr 24, 2013 at 06:40 AM

You could us a raycast, or just use unity's GUI(grap$$anonymous$$cal user interface)

 funtion OnGUI()
 {
     if(GUI.Button(Rect(100,100,100,100),"Multiplayer"/*Or your button texture*/))
     {
         //Application.LoadLevel("LoadingCampaign");
     }
 }
Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

14 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

This is not possible to be called for standalone input. Please check your platform and code where this is called (C#) 2 Answers

Detect if player wants to pause or to jump 3 Answers

Animation not working when UI buttons are pressed 0 Answers

2 players. Controlling just 1. 3 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