I am new to Unity and C#. I have a script here for a card game where my card is supposed to move up and down when the pointer is hovered over the card. But when my point hovers over each card, they all move up together and not separately. They also move when they touch other UI elements, regardless of what they are. I am doing something wrong but I don't know what.
Here is my code:
//My Codes I needs help on.
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class Mouse_Detector_Temp : MonoBehaviour {
public bool hovered;
// Use this for initialization
void Start ()
{
hovered = false;
}
// Update is called once per frame
void Update ()
{
//This checks to see if you are hovered over.
if (EventSystem.current.IsPointerOverGameObject ())
{
Debug.Log(gameObject);
if (hovered == false)
{
transform.Translate(0,10,0);
hovered = true;
}
}
else
{
if (hovered == true)
{
transform.Translate(0,-10,0);
hovered = false;
}
}
}
}
Additional Information: This code is run UI elements that are part of a Canvas (only way to do it, so that should be obvious).