I am new to C Sharp, Unity3D, and Unity Answers. I am a somewhat decent learner so I hope you guys can help me understand how to do this.
I am trying to make an object appear on hovering over a block with this script attached to it, and disappear when the mouse is not hovering over it. I thought I could make it simple by disabling the GameObject ingame while detecting the mouse using OnMouseEnter
and OnMouseExit
. It appears either the script is too simple, or I am doing it wrong.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelChangeState : MonoBehaviour {
public GameObject Sel;
public GameObject Sel2;
void Start () {
Sel.SetActive(false);
Sel2.SetActive(false);
}
void OnMouseEnter () {
Sel.SetActive(true);
Sel2.SetActive(false);
}
void OnMouseExit ()
{
Sel.SetActive(false);
Sel2.SetActive(true);
}
}
This script also changes another object known as Sel2.
I cannot figure out how to get this working. Is this even possible? Am I doing it wrong? This isn’t the right way to go, is it?