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;
- public bool encendida;
- public Camera cam;
- public Camera CamaraPrincipal;
- public float bateria = 100f;
- bool bateriaBaja = false;
- public float Rango = 2f;
- void Start () {
- }
- void Update () {
- RaycastHit hit;
- if (Physics.Raycast (cam.transform.position, cam.transform.forward, out hit, Rango)) {
- var item = hit.transform.GetComponent <Item> ();
- if (Input.GetKeyDown (KeyCode.Mouse0)) {
- item.tomaritem ();
- }
- }
- luz.enabled = encendida;
- if (Input.GetKey (KeyCode.Mouse1)) {
- CamaraPrincipal.fieldOfView = 40f;
- } else {
- CamaraPrincipal.fieldOfView = 60f;
- }
- if (Input.GetKeyDown (KeyCode.F) && !bateriaBaja){
- encendida = !encendida;
- }
- if (encendida) {
- bateria -= 0.12f;
- }
- if (bateria <= 5f && !bateriaBaja){
- StartCoroutine (AcabandoBateria ());
- }
- if (bateria >= 100f) {
- bateria = 100f;
- }
- if (bateria <= 0f) {
- bateria = 0f;
- luz.enabled = false;
- bateriaBaja = true;
- encendida = false;
- } else {
- bateriaBaja = false;
- }
- }
- IEnumerator AcabandoBateria () {
- yield return new WaitForSeconds (0.5f);
- encendida = false;
- yield return new WaitForSeconds (0.5f);
- encendida = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement