Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 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 this 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 this script so that when I go to click on this, it loads only this 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
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
1

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

Hi, You might want to consider using GUI.Button for this,

     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 this helps.

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
1

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 which is not what you want.

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

Or you can find the position by sending a raycast.

This has been asked a lot from before so try searching before asking :)

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 deltamish · Apr 24, 2013 at 06:39 AM

Hi you can achieve 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
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 HunterKrech · Apr 24, 2013 at 06:40 AM

You could us a raycast, or just use unity's GUI(graphical user interface)

 funtion OnGUI()
 {
     if(GUI.Button(Rect(100,100,100,100),"Multiplayer"/*Or your button texture*/))
     {
         //Application.LoadLevel("LoadingCampaign");
     }
 }
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

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

Changing Color of Material with Bool and Unity UI 1 Answer

How to make a button in FPS 1 Answer

I want the gameobject field of my persistent listeners to reference an object other than the one they are on. Is this possible? 1 Answer

How can I stop getting mouse position of Ui Elements? 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