using System.Collections; using System.Collections.Generic; using UnityEngine; public class lightonoff : MonoBehaviour { public GameObject txtToDisplay; //display the UI text
private bool PlayerInZone; //check if the player is in trigger public GameObject lightorobj; private void Start() { PlayerInZone = false; //player not in zone txtToDisplay.SetActive(false); } private void Update() { if (PlayerInZone && Input.GetKeyDown(KeyCode.F)) //if in zone and press F key { lightorobj.SetActive(!lightorobj.activeSelf); gameObject.GetComponent().Play(); gameObject.GetComponent().Play("switch"); } } private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Player") //if player in zone { txtToDisplay.SetActive(true); PlayerInZone = true; } }
private void OnTriggerExit(Collider other) //if player exit zone { if (other.gameObject.tag == "Player") { PlayerInZone = false; txtToDisplay.SetActive(false); } } }
my player is just a camera since im doing a fnaf style game, how can i get it to have a collider? Because its not working right now. Also my player tag is set.
@@ebenkotke6184 i think i just made another public game object and called it light 2 or something. i did this a very long time ago tho so dont take my word on that
@@ebenkotke6184 You could just use a simple empty object, and put all lights as it's child. That way if you set that gameObject to false, all lights will go out.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class lightonoff : MonoBehaviour
{
public GameObject txtToDisplay; //display the UI text
private bool PlayerInZone; //check if the player is in trigger
public GameObject lightorobj;
private void Start()
{
PlayerInZone = false; //player not in zone
txtToDisplay.SetActive(false);
}
private void Update()
{
if (PlayerInZone && Input.GetKeyDown(KeyCode.F)) //if in zone and press F key
{
lightorobj.SetActive(!lightorobj.activeSelf);
gameObject.GetComponent().Play();
gameObject.GetComponent().Play("switch");
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player") //if player in zone
{
txtToDisplay.SetActive(true);
PlayerInZone = true;
}
}
private void OnTriggerExit(Collider other) //if player exit zone
{
if (other.gameObject.tag == "Player")
{
PlayerInZone = false;
txtToDisplay.SetActive(false);
}
}
}
.
real for this
THANK U SO MUCH!!!!!!!!!! THIS HELPED A LOTTTTTTTTT
DUDE U R THE BEST
my player is just a camera since im doing a fnaf style game, how can i get it to have a collider? Because its not working right now. Also my player tag is set.
Just add a empty gameobject with a collider to the camera
very helpful, ty !
thank you so much!!!!
Hey everything seems to be working but the player cannot enter the hitbox of the button?
oof, forgot to click is trigger.. but now the button doesent stop clickinG
Try instructions again
Make sure player tag is set, and your using the script I provided
Just wondering how would I make it to have more than one lightorobj I want to have more than one light all connected to one switch?
Never mind just found out how to but thanks so much :))))
@@Robocal ik this was long ago but how>????
@@ebenkotke6184 i think i just made another public game object and called it light 2 or something. i did this a very long time ago tho so dont take my word on that
@@ebenkotke6184 You could just use a simple empty object, and put all lights as it's child. That way if you set that gameObject to false, all lights will go out.
TY SO MUCH! THE gameObject.GetComponent().Play("switch"); is all what i need this whole time! Much love!!!♥