- Home /
PopUp Monster
This script highlights objects when you mouseOver them. I am trying to add the function that if you click your mouse on the highlighted object, another one will activate(A Child) and play its animation. The pop up isn't working right at all, any ideas?
public GameObject popUp;
void Start () {
popUp = GameObject.FindWithTag ("Monster");
}
public void OnMouseEnter(){
HighLight (true);
Monster (true);
}
public void OnMouseExit(){
HighLight (false);
Monster (false);
}
public void Monster (bool appear){
Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit rayCastHit;
if(Physics.Raycast(ray.origin, ray.direction, out rayCastHit, Mathf.Infinity))
{
Monster monster = rayCastHit.transform.GetComponent<Monster>();
if(monster)
{
if(appear)
{
if (Input.GetMouseButton (0)) {
popUp.SetActive (true);
monster.PlayMonsterAnim();
} else {
popUp.SetActive (false);
}
}
}
}
}
Answer by Cherno · Mar 08, 2015 at 09:46 PM
Use .enabled = true or false instead of SetActive.
Insert Debug.Log lines to see where your code stops working the way you want.
Thanks for the answer, I ended up breaking it down into two scripts after seems to work.
I just noticed that .enable doesn't work for GameObjects anymore with Unity5, so you were right using SetActive.
Your answer
![](https://koobas.hobune.stream/wayback/20220613185527im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I focus on mouse control without having to click? 0 Answers
(4.6 UI) How to highlight a character/unit when moused over? 1 Answer
Overlapping GUI Button priority 3 Answers
OnPointerEnter/OnPointerExit does not update when mouse is not moveing? 1 Answer
Drawing Sector around GameObject in GameView: GUITexture or 3D Object 1 Answer