Untitled
unknown
csharp
2 years ago
1.9 kB
7
Indexable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Flashlight_Control : MonoBehaviour
{
[SerializeField] private Light flashlight;
private float blinkDelay = 0.0f;
[SerializeField] private bool useBatteries;
private Player_Control pc;
public bool isBlinking, blinkOn;
private float timer;
private void Start()
{
pc = GetComponent<Player_Control>();
flashlight.enabled = false;
}
private void Update()
{
if(pc.lightIsOn && !flashlight.enabled)
{
flashlight.enabled = true;
}
if(!pc.lightIsOn && !isBlinking)
{
flashlight.enabled = false;
}
if (isBlinking) Blinking();
}
void Blinking()
{
timer += Time.deltaTime;
if(timer >= blinkDelay)
{
ToggleLight();
blinkDelay = Random.Range(0.125f, 0.5f);
timer = 0f;
}
}
void ToggleLight()
{
blinkOn = !blinkOn;
flashlight.intensity = blinkOn ? 6.0f : Random.Range(1.0f, 4.0f);
}
public void SetBlinking(bool b)
{
isBlinking = b;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Trigger_Action : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
Flashlight_Control fc = other.GetComponent<Flashlight_Control>();
fc.SetBlinking(true);
}
}
private void OnTriggerExit(Collider other)
{
if (other.tag == "Player")
{
Flashlight_Control fc = other.GetComponent<Flashlight_Control>();
fc.SetBlinking(false);
}
}
}
Editor is loading...
Leave a Comment