If object is active, destroy text
I have a scene where you enter a trigger to turn on a lamp, LightText pops up saying "Press E to turn on light" then it toggles it on and off. I want a UI called Task1 saying "Turn on the light" to pop up at the start, then when the light is active, the text is destroyed or enabled. Why isn't this working? thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LightScript : MonoBehaviour {
public GameObject Light;
public Text LightText;
public Text Task1;
void Start()
{
LightText.enabled = false;
Task1.enabled = true;
Light.SetActive(false);
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
LightText.enabled = true;
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
LightText.enabled = false;
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.E) && (LightText.IsActive()))
{
if(!Light.activeSelf)
{
Light.SetActive(true);
}
else
Light.SetActive(false);
}
if (Light.IsActive)
Task1.enabled = false;
}
}
Which part of this isn't working? Just the "Turn On the Light" part?
EDIT: I think your problem is with line 45 "if(Light.IsActive)". You need to use if(Light.activeSelf) there ins$$anonymous$$d because there is no IsActive method for a GameObject.
Your answer
Follow this Question
Related Questions
Loot table problems 1 Answer
Game crashes on iPhone 11 0 Answers
Need help with Mute Button 1 Answer
How do i have game object in the middle of a Catmull spline? 0 Answers
how to move a rigidbody ball or kick a ball from swipe gesture 0 Answers