I want a green spotlight thing to enable when I press ‘tab’. Here is the code I have so far. This script is on the green spotlight itself.
using UnityEngine;
using System.Collections;
public class SelectPlayer : MonoBehaviour
{
// Use this for initialization
void Start ()
{
if(Input.GetKey(KeyCode.Tab))
{
gameObject.SetActive(true);
}
}
// Update is called once per frame
void Update ()
{
}
}
Nothing happens when I press tab. I’ve tried setting the GameObject on and off manually in-client before testing, and either way it doesn’t work. Thanks in advance!
This will set gameobject active state to opposite. Notice, that you will be able only
to disable the gameobject, as disabled components aren’t updated, “Update is called” wont be called. So in this case there’s really no way of re-enabling the gameobject from same gameobject.
The solution is to process SetActive() from other gameobject with active state is always true.
It can either be parent or completely separate gameobject.