Question by
brt88 · Aug 17, 2017 at 04:13 PM ·
c#unity 5gameobjectactive
how do i check if a gameobject is not active?
How do i check if the lantern is not active? i think my code is good, but i supouse i'm not taking into acount something :v
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Linterna : MonoBehaviour {
public GameObject lantern;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.L) && lantern.activeSelf)
{
lantern.SetActive(false);
}
else if (Input.GetKey(KeyCode.L) && !lantern.activeSelf)
{
lantern.SetActive(true);
}
}
}
Comment
Answer by unidad2pete · Aug 17, 2017 at 04:18 PM
Its fine, but carefull, Input.GetKey its called each frame , set to Input.GetKeyDown for sure call function only one time. And make sure to set a reference to lantern gameobject. If you need something on Spanish you can send me a private message ;)