Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

314
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda