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 /
  • Help Room /
avatar image
0
Question by gllybeean · Feb 05, 2018 at 10:09 AM · rotationevent triggering

How to stop a rotating object on pointer enter?

I am working with this VR application where I have this rotating globe that I want to stop when the reticle pointer enter or hover on it and then will continue on rotating once the on reticle pointer exit. I did try using this code that I found here also:

public class stopRotation : MonoBehaviour {

 public bool rotateObject = true;
 public float speed = 5f;
 
 void Update(){
         transform.Rotate (0, speed, 0);
 }

 void OnPointerEnter(){
     rotateObject = false;
 }

 void OnPointerExit(){
     rotateObject = true;
 }

}

Originally its function was OnMouseOver and OnMouseExit, it worked but then when I ran it on my android phone, the stop rotation didn't work. So I changed function to OnPointerEnter and OnPointerExit but it didn't work. Please help.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Zodiarc · Feb 05, 2018 at 10:18 AM

OnPointerEnter is for UI elements. You should use OnMouseEnter and OnMouseExit.

Comment
Add comment · Show 5 · 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 gllybeean · Feb 05, 2018 at 10:39 AM 0
Share

But On$$anonymous$$ouseEnter and On$$anonymous$$ouseExit are not working when it is exported to android app.

avatar image Zodiarc gllybeean · Feb 05, 2018 at 10:41 AM 0
Share

Then use Touch

avatar image gllybeean Zodiarc · Feb 05, 2018 at 10:46 AM 0
Share

Is Touch possible on VR apps?

Show more comments
avatar image
0

Answer by meat5000 · Feb 05, 2018 at 10:57 AM

To use OnPointerEnter etc you must add the Interface for it to work.

Something like in here

https://answers.unity.com/questions/1083857/how-to-drag-a-ui-object.html


https://answers.unity.com/questions/998848/onmouseenter-not-working-on-ui-elements.html

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 cloud_canvas · Apr 04, 2018 at 07:54 PM

(This answer was written as of Unity 2017.3.1.)

Hi @gllybeean ! So, there's a couple of things here:

  1. The boolean rotateObject that you've defined is not controlling any logic. You need to make running transform.Rotate(0, speed, 0); in the Update() loop dependent upon rotateObject being true.

  2. OnPointerEnter and OnPointerExit depend upon your class implementing the IPointerEnterHandler and IPointerExitHandler interfaces from UnityEngine.EventSystems.

All in all, here's what your script should look like:

 using UnityEngine;
 using UnityEngine.EventSystems;    // you need this for pointer events
 
 public class stopRotation : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler    // inherits from pointer event interfaces in addition to just being a simple MonoBehaviour that does everything a basic Unity script does
 {
     public bool rotateObject = true;
     public float speed = 5f;
  
     void Update()
     {
         if (rotateObject)    // this is the same as saying "if (rotateObject == true)"
         {
             transform.Rotate (0, speed, 0);
         }
     }
  
     public void OnPointerEnter(PointerEventData eventData)    // you don't need to know anything about the pointer event, just that it happened.
     {
         rotateObject = false;
     }
 
     public void OnPointerExit(PointerEventData eventData)    // so although you get an object of type PointerEventData passed to you when this happens, you can ignore it.
     {
         rotateObject = true;
     }
 }
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

104 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why are the pivots for my sprites always off-center? 1 Answer

Parenting an object causes it to change rotation 1 Answer

UI compass pointing to a 3D object 0 Answers

How do i fix this default rotation? 0 Answers

Sprites only rotate by 90 degrees 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