Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
Hover over one button affects other button as well

I have two buttons like so: enter image description here

I am using DOTween so that when I hover over the button it highlights by enlarging slightly and tweens into it to look smooth. However, I have two separate scripts attached for each button which do exactly the same thing but when I hover over one of the buttons the other button also enlarges. I've tried using the buttons under the same canvas which didn't work. So then I tried using two canvases for separate buttons and it still the same issue. Looks like this: https://vimeo.com/user105553995/review/517200220/41fbe8d619

My code is in different scripts for each button but exactly the same:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using DG.Tweening;
public class OtherButton : MonoBehaviour
{
    // Start is called before the first frame update
    private Vector3 defaultScale;
    // Start is called before the first frame update
    void Start()
    {
        defaultScale = this.transform.localScale;
    }

    // Update is called once per frame
    void Update()
    {
        WhilePointerHover();
    }
    private void WhilePointerHover()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            Vector3 enlarge = defaultScale*1.2f;
            this.transform.DOScale(enlarge, 0.05f);
            Debug.Log(this.gameObject.name);
            
        }
        else
            this.transform.localScale = defaultScale;
    }
}

Any help is appreciated!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Code checks if you are over any UI object, so any script will react.

You should use https://docs.unity3d.com/2019.1/Documentation/ScriptReference/UI.Selectable.OnPointerEnter.html

And

https://docs.unity3d.com/2019.1/Documentation/ScriptReference/UI.Selectable.OnPointerExit.html

So it will only react to the object to which it is attached to. Note that the Image or Button component needs to be on same object.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!