Search Unity

Void OnMouseDown not working in Prefab

Discussion in 'Prefabs' started by Louis_Amerongen, Mar 22, 2019.

  1. Louis_Amerongen

    Louis_Amerongen

    Joined:
    Jul 21, 2017
    Posts:
    19
    Hi,

    When I try to run the script with Void OnMouseDown attached to a GemaObject this works. When I instantiate the same object, OnMouseDown doesn't run.

    Is there a solution to this problem?



    Code (CSharp):
    1.  
    2. public class ActivateWhenClick : MonoBehaviour
    3. {
    4.     public GameObject Activate;
    5.     private bool Show;
    6.  
    7.  
    8.  
    9.  
    10.     public void OnMouseDown()
    11.     {
    12.         if(Show == true)
    13.         {
    14.             Activate.SetActive(true);
    15.             Show = false;
    16.         }
    17.         else if (Show == false)
    18.         {
    19.             Activate.SetActive(false);
    20.             Show = true;
    21.         }
    22.     }
    23. }
    Thanks in advance,

    Louis