When i show&hidden gameobject.active by gameobject.active.
but the OnEnable() of GameObject only be called once in first times.
have any function to get the response when the value gameobject.active be changed?
gregzo
2
My test project is very simple - and uses your code
GameObject1 has attached component Script1:
using UnityEngine;
using System.Collections;
public class Script1 : MonoBehaviour {
public GameObject obj;
void show()
{ obj.active = true; }
void hidden()
{ obj.active = false; }
// Update is called once per frame
void Update ()
{
if(Input.GetKeyDown ("space"))
{
if(obj.active)
{
hidden();
}
else{
show ();
}
}
}
}
GameObject2 has attached Script2 :
using UnityEngine;
using System.Collections;
public class Script2 : MonoBehaviour {
void Start (){ }
void Update (){ } //be careful, even empty updates have a cost
void OnEnable ()
{ Debug.Log(this.name+":Enable"); }
void OnDisable()
{ Debug.Log(this.name+":Disable"); }
}
It works.
P.S. Deleted other posts for clarity.