Hello i am still a begginer in scripting and i am looking trought some tutorial to make some test.
i am actually working on a script that hide a canvas when the player is on a zone or not (a light bulb that is Lighten when the player is in the light or not)
Its made from 2 script (one on the player itself and one on every light source with a sphere collider set to trigger)
LightCanvas is parented to another canvas.
Here’s the one on the player
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class InLight : MonoBehaviour {
public bool OnOff;
private GameObject lightUI;
void Start ()
{
SetInitialReferences ();
}
public void Inlight()
{
if(OnOff = true)
{
lightUI.SetActive(true);
Debug.Log ("On");
}
}
public void Outlight()
{
if(OnOff = false)
{
lightUI.SetActive(false);
Debug.Log ("Off");
}
}
void SetInitialReferences()
{
lightUI = GameObject.Find("LightCanvas").GetComponent<Canvas>();
}
}
and here’s the one on every light source:
using UnityEngine;
using System.Collections;
public class LightZone : MonoBehaviour
{
private InLight illumination;
void Start ()
{
SetInitialReferences();
}
void OnTriggerEnter (Collider other)
{
illumination.Inlight ();
//Debug.Log (other.name+" is in the light");
}
void OnTriggerExit (Collider other)
{
illumination.Outlight ();
//Debug.Log (other.name+" is in the Dark");
}
void SetInitialReferences()
{
illumination = GameObject.Find("Player1").GetComponent<InLight>();
}
}
I get that error in the console:
Assets/MyAsset/Scripts/InLight.cs(35,17): error CS0029: Cannot implicitly convert type UnityEngine.Canvas' to
UnityEngine.GameObject’