I tried this thread already in the OnGUI forum but didn´t got any response there. So i try it here again.
It did sound very simple to me in the beginning…but somehow i mixed it up too much.
I have a scene with a few buttons and some objects.
I want that when i mouse hover over button1…object1 appears…otherwise the object1 is invisible.
using UnityEngine;
using System.Collections;
public class ShowTown : MonoBehaviour {
public GameObject place = null;
private void OnMouseOver()
{
if (place != null && place.gameObject != null) {
place.gameObject.SetActive(true) = place.gameObject.SetActive(false);
}
}
}
// toggle
place.gameObject.SetActive(!place.gameObject.activeSelf);
// set true
place.gameObject.SetActive(true);
// set false
place.gameObject.SetActive(false);
you can’t assign a value to a function call…
if you want it to appear when you mouse over, and disappear when you move the mouse away you want to set it true in the OnMouseOver and false in the OnMouseExit functions
Thanks for all the help , at least i dont get any compile errors anymore. It currently still doesn´t work , and stays on all the time…but i hope i figure that out very soon.
OnMouseOver is actually supposed to be OnMouseEnter I think (unless you want it to get called every single frame that the mouse is over the control, rather than just the first frame), and I’m not sure they’re allowed to be private. You might also be missing a closing brace, possibly.