SomeObject stays active?
Script 1 works, Script 2 works, but Script 3 doesn’t work. It seams that script 2 keeps the object SomeObject active.
Debug.Log in Script 3 gives that it works just as it supposed to be, but the object SomeObject doesn’t set to false.
How can I set the SomeObject.SetActive to false in Script 2, witch I thing that this would be the problem.
-----Script1-----
public float interactDistants = 5f;
void Update ()
{
if (Input.GetKeyDown (KeyCode.O))
{
Ray ray = new Ray (transform.position, transform.forward);
RaycastHit hit;
if (Physics.Raycast (ray, out hit, interactDistants))
{
if (hit.collider.CompareTag ("SomeTag"))
{
hit.collider.transform.GetComponent<SomeScript>().ChangeVisibleState ();
}
}
}
}
-----Script2_____
using UnityEngine;
using System.Collections;
public class SomeScript : MonoBehaviour {
public GameObject SomeObject;
public void ChangeVisibleState ()
{
active = !active;
}
void Update ()
{
if (active)
{
SomeObject.SetActive (true);
}
if (active == false)
{
SomeObject.SetActive (false);
}
}
}
-----Script 3-------
using UnityEngine;
using System.Collections;
public class FirehoseActivator : MonoBehaviour {
public GameObject SomeObject;
void OnTriggerEnter(Collider col)
{
if (col.gameObject == EmptyObject)
{
//Debug.Log(SomethingOutSetActiveFalse);
SomeObject.SetActive (false);
if (col.gameObject == EmptyObject)
{
//Debug.Log(SomethingOutSetActiveTrue);
SomeObject.SetActive (true);
}
}
}