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 /
avatar image
0
Question by MandibleDEV · Jun 13, 2016 at 06:06 AM · c#scripting problem

How to make a GameObject a button?

I'm developing a game in which you have to find a button in a room, for the script i'm using this and just putting it on the button

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 
 public class OnClickLoadNextLevel : MonoBehaviour {
     void OnMouseUpAsButton() {
         SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex + 1);
     }
 }
 





but this creates some weird bug where you can't be too close to the button to click it, and it sometimes takes a few clicks to find the point at which it works, is there any other way i could do this? If you wan't to see the bug yourself go to ►http://gamejolt.com/games/find-the-button/155300

Comment
Add comment · Show 2
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 ninja_gear · Jun 14, 2016 at 01:30 AM 0
Share

I didn't get past level 4, but other than that the button always behaved like I expected it to.

avatar image MandibleDEV ninja_gear · Jun 14, 2016 at 01:36 AM 0
Share

If you look at a few of the LP's in the comments you can see others have the same problem, it happens with every build, try to get close to the button

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Brijs · Jun 13, 2016 at 07:06 AM

Use OnMouseDown() method of monobehaviour

It will be called when you click gameobject

Write your code in this method

reference : OnMouseDown

Comment
Add comment · Show 3 · 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 MandibleDEV · Jun 13, 2016 at 08:34 PM 0
Share

This still has the bug happen, is there another way or do i have to just suck it up lol

avatar image umuur MandibleDEV · Jun 13, 2016 at 11:43 PM 0
Share

can you share us the bug? On$$anonymous$$ouseDown looks perfectly fit to your project.

avatar image MandibleDEV umuur · Jun 14, 2016 at 01:37 AM 0
Share

it won't work if you're too close to the button or sometimes just doesn't work completely.

avatar image
0

Answer by noorudheen · Jun 14, 2016 at 03:29 AM

in ufps demo, there is a button implementation. i think they are using raycast.

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 MandibleDEV · Jun 14, 2016 at 03:39 AM 0
Share

How would i use raycast for this? send a ray from the mouse and detect if the name is Button?

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Enable/Disable part of script with Button? 0 Answers

How to translate object using script? 1 Answer

Unloading Broken Assembly | How to solve this !? 2 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