Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 riskaanisah · Nov 14, 2018 at 09:11 AM · onmousedownonmouseoveronmouseenteronmouseuponmouseexit

OnMouseOver Problem

 public class ButtonTrigger : MonoBehaviour {
     public GameObject karakter;
     public GameObject ButtonLevel1;
 
     private void OnMouseOver()
     {
         if (Input.GetMouseButton(0))
         {
             karakter.SetActive(true);
             ButtonLevel1.SetActive(true);
         }
     }
 
     private void OnMouseOver2()
     {
         if (Input.GetMouseButton(0))
         {
             //...
         }
     }
 }

hello I have 3 buttons in the form of 3 dimensions. so I use onmouseover to be able to move to the next scene. but what about the correct code? because I entered the onmouseover code for three buttons in one code he can't, do I have to separate it?alt text

bu.jpg (20.0 kB)
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 Hellium · Nov 14, 2018 at 09:23 AM 0
Share

Are you sure the objects have a collider?

avatar image riskaanisah · Nov 14, 2018 at 09:25 AM 0
Share

yes all objects already have collider

avatar image riskaanisah · Nov 14, 2018 at 10:04 PM 0
Share

my problem is on the if-statement, I can't make it read, when I click object 1 or 2 or 3, please help me

3 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by SkaredCreations · Nov 14, 2018 at 03:43 PM

You should handle Input methods (like GetMouseButton) inside Update or FixedUpdate in general. You could try to move your logic inside OnMouseDown instead (anyway "OnMouseOver" doesn't exist, I suppose you meant "OnMouseEnter").

Comment
Add comment · Show 2 · 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 Hellium · Nov 14, 2018 at 06:37 PM 0
Share

https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.On$$anonymous$$ouseOver.html

avatar image SkaredCreations Hellium · Nov 15, 2018 at 06:22 PM 0
Share

Ops, sorry I forgot about it and confused with On$$anonymous$$ouseEnter ;)

avatar image
0

Answer by kaosermail · Nov 26, 2018 at 11:55 AM

First I would check with a print if it enters the function:

 private void OnMouseOver()
      {
          print(gameObject.name);
      }

If that doesn't work, check colliders and check the script is on each button.

That should work, you don't need to separate the code.

Tell me if that works, pls!

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 brunopava · Nov 26, 2018 at 01:04 PM

What I would do is something like this:

 using UnityEngine;
 using UnityEngine.Events;
 
 //Attach this to all three buttons
 public class TriggerButton : MonoBehaviour 
 {
     public CustomEvent onMouseDown;
 
     private void Awake()
     {
         //Register StandardAction() function to the listener.
         //This is an example using code to add the listener
         //But you can also drag and drop in the editor just like the UI button actions.
         //This way you can use this script for multiple purposes
         onMouseDown.AddListener(StandardAction);
     }
 
     private void Update()
     {
         if(Input.GetMouseButtonDown(0))
         {
             //Invokes all functions that were registered to the listener
             onMouseDown.Invoke();
         }
     }
 
     //Your stuff
     private void StandardAction()
     {
         Debug.Log("DO YOUR OWN STUFF HERE :D");
     }
 }
 
 //This is to make the event appear in the editor
 [System.Serializable]
 public class CustomEvent : UnityEvent {}
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

96 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

Related Questions

OnMouseDown 2 Answers

Instantiate object OnMouseOver, then delete the instantiated object OnMouseExit. 1 Answer

Changing the Mouse's Range for OnMouse events 0 Answers

Making a tray GameObject that slides out on mouse over 1 Answer

Multiple GUI textures one script 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