Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Linterna : MonoBehaviour
- {
- public Light luz;
- AudioSource sm;
- public AudioClip sound;
- public GameObject LinternaOBJ;
- [Range (0, 100)]public float CurBateria;
- public int Baterias;
- public bool isOn;
- [Range(0, 100)] public float Rbateria;
- public bool BatteryLow;
- bool wait;
- void Start()
- {
- sm = gameObject.AddComponent<AudioSource>();
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.F) && LinternaOBJ.active == true)
- {
- sm.PlayOneShot(sound, 1f);
- isOn = !isOn;
- }
- if (CurBateria <= 15f && Baterias > 0 && Input.GetKeyDown (KeyCode.R))
- {
- CurBateria += 100;
- Baterias--;
- }
- if (CurBateria <= 10f)
- {
- BatteryLow = true;
- if (!wait)
- {
- StartCoroutine(parpadeo());
- wait = true;
- }
- }
- else
- {
- BatteryLow = false;
- }
- if (isOn)
- {
- CurBateria -= Rbateria * Time.fixedDeltaTime;
- }
- if (CurBateria <= 0)
- {
- isOn = false;
- }
- if (!wait) {
- luz.enabled = isOn;
- }
- CurBateria = Mathf.Clamp (CurBateria, 0, 100);
- }
- IEnumerator parpadeo()
- {
- if (BatteryLow)
- {
- luz.enabled = false;
- yield return new WaitForSeconds(0.8f);
- luz.enabled = true;
- wait = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement