Hello!
Im making horror game. I want to make a flashlight which will be ON (till the end of the game) after collecting it from shelf. I know how to make a normal flashlight (attach spotlight to player or something else) but i dont have any script for it etc etc. If u want u can link here free flashlight model too Thanks in advance
I have never made this myself but perhaps if you made the condition of it being on or off attached to a bool? So basically:
void Start(){
lampon=false;
}
void Update(){
if (pickuplamp=true){
lampon=true;
}
}
?
Iβm new here but I got this simple idea , u creat two flashlights , one set it inactive at the start of the game and make it already attached to the player and the other one in the shelf or whatever u wanna put it , anyway add a bool variable to your player and add a methode which only functions if the bool is ture that sets the first flashlight to active β¦ one ore thing u can destroy the one you collected
attach this script to your Character .
public class FlashLight: MonoBehaviour {
public GameObject FlashLight // the one attached to the player
private bool FlashLight_collected ;
void Start() {
FlashLight.SetActive(true) ;
}
void Update(){
/* The following code means ones u collected the FlashLight the one attached to the player will be
set to active */
if (FlashLight_collected && !FlashLight.active){
FlashLight.SetActive(true) ;
}
}
void OnTriggerEnter(Collider collider){
if (collider.CompareTag("FlashLight")) {
DestroyObject(collider.gameobject) ;
FlashLight_collected = true ;
// you can improve it by setting a bool to true and once u r out of the colliders it set it to false and
add another methode which allows u to click on a specific key to collect that Flashlight
}
}
}
Iβm new as well and Iβm not used to write stuff in the forum so Iβm sorry if I wasnt clear enough or if I had some mistakes in the code . Try it ur self just copy the idea and make ur own code doesnt matter if itβs unoptimized just try to understand and learn how to code . Iβm like 18 days in unity and I never coded before , Only some python in the uni but I can apply most of my ideas now