Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Juanitoalcachofa90 · Oct 24, 2016 at 10:05 PM · c#javascriptguispotlightflashlight

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 ;)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges