- Home /
Cursor / MouseOver Glitch
Hello!
I have switches that turn on if the player clicks from a near distance. A simple Cursor displays when MouseisOver.
The thing worked with a simple object, but now it's a little more complicated Mesh I made, the Cursor goes Displayed/Hidden veeery fast, and thus activating the Switch is also hard, because you have to click when the Cursor is Displayed... which makes it random.
Here's the script, it's a true riddle, I went over every object and can't find the source. The Collider of the Switch is a simple Capsule collider (not trigger).
 void OnMouseOver()
     {
         mouseIsOver = true;
     }
 
     void OnMouseExit()
     {
         mouseIsOver = false;
         Cursor.SetCursor(null, Vector2.zero, cursorMode);
     }
 
     void Update()
     {
         if (shutdown)
         {
             if (Light.activeInHierarchy == true) //prevents from Update Shutdown
             {
                 Shutdown();
             }
             else return;
         }
 
         if (mouseIsOver)
         {
             float dist = Vector3.Distance(gameObject.transform.position, player.position);
             if (dist <= 2f)
             {
                 hasPlayer = true;
                 Cursor.SetCursor(cursorTexture, hotSpot, cursorMode);
                 if (hasPlayer && Input.GetMouseButtonDown(0))
                 {                    
                     if (Light.activeInHierarchy == false)
                     {
                         anim.SetBool("ON", true);
                         Cursor.SetCursor(cursorTexture, hotSpot, cursorMode);
                         Light.SetActive(true);
                         state.lightsOn += 1;
                     }
                     else if (Light.activeInHierarchy == true)
                     {
                         anim.SetBool("ON", false);
                         Cursor.SetCursor(cursorTexture, hotSpot, cursorMode);
                         Light.SetActive(false);
                         state.lightsOn -= 1;
                     }
                 }
             }
             else
             {
                 hasPlayer = false;
             }
         }       
     }

What is your hotspot? I found that the cursor glitches a bit when hotspot changes, due to the new cursor having to reposition to counter to difference between the previous and the new hotspot. Unfortunately it seems to take 1 frame, and it's not easy to move the cursor manually to fix that in advance.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                