- Home /
Luz parpadeante con bateria
hola tengo un pequeño gran problema. tengo dos scripts: uno es de una luz parpadeante (FlickeringFlashlight) y el otro de la bateria de la linterna el problema es que el script de bateria crea su propia light y el FlickeringFlashlight tambien y lo que quiero es convinar los dos scripts para que quede que la bateria de la linterna dure 2 minutos, que cuando este en 10% empiece a parpadear y se apague y con cualquier tecla se restaure.
[Google translation]
Flashing light with battery hello I have a little big problem. I have two scripts: one is of a flashing light (FlickeringFlashlight) and the other battery flashlight the problem is that the script battery creates its own light and FlickeringFlashlight well and what I want is convinar the two scripts to make it the flashlight battery lasts 2 minutes, that when 10% starts flashing on and off and any key is restored.
#pragma strict
var minWorkingTime : float = 60.0;
var maxWorkingTime : float = 120.0;
var minLightIntensity : float = 0.5;
var maxLightIntensity : float = 2.5;
private var startIntensity : float = 1.85;
enum flashlightState { IsWorking, Flickering, Resetting }
var currentState : flashlightState;
private var workingTimer : float = 0.0;
private var workingTimeLimit : float = 90.0;
var minFlickerSpeed : float = 0.05;
var maxFlickerSpeed : float = 0.2;
private var flickerCounter : float = 0.0;
private var resetTimer : float = 0.0;
function Start()
{
workingTimeLimit = Random.Range( minWorkingTime, maxWorkingTime );
GetComponent.<Light>().enabled = true;
startIntensity = GetComponent.<Light>().intensity;
currentState = flashlightState.IsWorking;
}
function Update()
{
switch( currentState )
{
case flashlightState.IsWorking :
IsWorking();
break;
case flashlightState.Flickering :
FlickerFlashlight();
CheckForInput();
break;
case flashlightState.Resetting :
Resetting();
break;
}
}
function IsWorking()
{
workingTimer += Time.deltaTime;
if ( workingTimer > workingTimeLimit )
{
flickerCounter = Time.time + Random.Range( minFlickerSpeed, maxFlickerSpeed );
currentState = flashlightState.Flickering;
}
}
function FlickerFlashlight()
{
if ( flickerCounter < Time.time )
{
if (GetComponent.<Light>().enabled)
{
GetComponent.<Light>().enabled = false;
}
else
{
GetComponent.<Light>().enabled = true;
GetComponent.<Light>().intensity = Random.Range(minLightIntensity, maxLightIntensity);
}
flickerCounter = Time.time + Random.Range( minFlickerSpeed, maxFlickerSpeed );
}
}
function CheckForInput()
{
if (Input.GetKeyDown(KeyCode.F))
{
currentState = flashlightState.Resetting;
}
}
function Resetting()
{
resetTimer += Time.deltaTime;
if ( resetTimer > 0.75 )
{
resetTimer = 0.0;
workingTimer = 0.0;
workingTimeLimit = Random.Range( minWorkingTime, maxWorkingTime );
GetComponent.<Light>().enabled = true;
GetComponent.<Light>().intensity = startIntensity;
currentState = flashlightState.IsWorking;
}
else if ( resetTimer > 0.65 )
{
GetComponent.<Light>().enabled = false;
}
else if ( resetTimer > 0.55 )
{
GetComponent.<Light>().enabled = true;
GetComponent.<Light>().intensity = startIntensity;
}
else if ( resetTimer > 0.25 )
{
GetComponent.<Light>().enabled = false;
}
else if ( resetTimer > 0.15 )
{
GetComponent.<Light>().enabled = true;
GetComponent.<Light>().intensity = startIntensity;
}
else if ( resetTimer > 0.05 )
{
GetComponent.<Light>().enabled = false;
}
}
ese es el de la FlickeringFlashlight
este es el de la bateria
using UnityEngine;
using System.Collections;
public class Linterna : MonoBehaviour {
public Transform Camara;
public bool SeguirCamara = true;
public KeyCode TeclaEncendido = KeyCode.F;
public Texture2D Icono;
public Texture2D IconoOff;
public int Bateria = 100;
float Bat = 100f;
public bool Activa;
public bool Debugs;
void Start(){
GetComponent<Light>().enabled = true;
gameObject.GetComponent<Light>().type = LightType.Spot;
Bat = (float)Bateria;
}
void FixedUpdate (){
if(Camara != null){
if(Activa){
if(Bat > 0)Bat -= 0.01f;
Bateria = (Mathf.CeilToInt(Bat));
if(Bateria < 1){
Activa = !Activa;
if(Debugs)if(Activa)print ("Linterna Activada"); else print ("Linterna Desactivada");
}
}else{
gameObject.GetComponent<Light>().intensity = 0;
if(Bat < 100f)Bat += 0.01f;
Bateria = (Mathf.CeilToInt(Bat));
}
}else{
print("No hay asignada una Luz o una Camara! Acurdate de Asignar un SpotLight");
}
if(Input.GetKeyDown(TeclaEncendido)){
Activa = !Activa;
if(Debugs)if(Activa)print ("Linterna Activada"); else print ("Linterna Desactivada");
}
}
void OnGUI(){
if(Icono != null)if(Activa)GUI.DrawTexture(new Rect(0,10,Screen.width/10,Screen.height/6),Icono);else GUI.DrawTexture(new Rect(0,10,Screen.width/10,Screen.height/6),IconoOff);
GUI.Label(new Rect(0+Screen.width/10,Screen.height/20,Screen.width/6,Screen.height/6),"Bateria :" +Bateria);
}
}
Gracias por su tiempo ;)
Your answer
Follow this Question
Related Questions
GUI text blinking opacity 1 Answer
GUI Problem 2 Answers
Setting Scroll View Width GUILayout 1 Answer
OnTriggerEnter not working for NavMesh 1 Answer
What Am I Doing Wrong? Variable Names 3 Answers