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 FGPArthurVII · Jan 06, 2015 at 09:19 AM · collisionbuttonscenemouseclick

How to make a button work?

Well, I have a main menu scene, three buttons, all of them are textures imported to the engine, all of them with it's own collision box. But I want to define that when I click at X button's collision box, we are going to the scene Y. How can I do that?

Comment
Add comment · Show 1
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 ramp · Jan 06, 2015 at 09:38 AM 0
Share

Hello, you make a action on button click.

if (GUI.Button(Rect(10,70,50,30),"Click"))

{

        Application.LoadLevel ("Y");

}

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Hexer · Jan 06, 2015 at 10:38 AM

You can also use OnMouseDown.

 function OnMouseDown()
 {
 Application.LoadLevel("Y");
 Debug.Log("Load Y");
 }
 
 

I prefer this method over using GUI.Button because with this method I can use any object or sprite as a button. Just be sure to add a collider to your object. For sprites you want to use BoxCollider2d or PolygonCollider2d.

Add this script to object "X"

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 FGPArthurVII · Jan 06, 2015 at 11:59 AM 0
Share

But How can I get these four cordinates of the rectangle?

avatar image KiraSensei · Jan 06, 2015 at 12:42 PM 0
Share

The collider you put in the game object will handle the coordinates, you don't have anything more to do after that.

avatar image FGPArthurVII · Jan 06, 2015 at 12:50 PM 0
Share

I'e used the way you said, and it works, but what I wanted to do is, I have the textures of the buttons placed on the scene in their right place with their right size, I wanted to make a scene change when I click their position or their collision box, How could I do that?

avatar image KiraSensei · Jan 06, 2015 at 12:55 PM 0
Share

You create a script containing this function On$$anonymous$$ouseDown, you attach it to the game object that contains the button texture and a collider, and it is over.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

help assinging a touch button to left click 0 Answers

Scene Change Collision 2 Answers

Analysing player metrics help 0 Answers

Mistake in Function with Collision and AddForce 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