Search Unity

Flashlight?

Discussion in 'Scripting' started by edplane, Oct 11, 2009.

  1. edplane

    edplane

    Joined:
    Jul 13, 2009
    Posts:
    485
    But its more expensive. And a 250 gig HD seems a little overkill. But they both have the same features, regardless of the clock speed. Also, its a little discuraging, seaming that if I had and Intel-based computer, capable of running windows, there would be no need to re-make the game I so loved and cherished for all these years, though, It would make a great tribute, and, could possibly, win one of those Unity 'Make something great this summer', and that would be killer, 5 grand and a pro license? YEA! lol, But the computer is really up to my folks, I just want to go easy and not drive them away from a great piece of equipment. and, besides, an extra 300 bucks for 300 MHz? How much of a differance will it make? Top off the RAM, and it could be faster than stock 2.53 GHz....
    Well, its almost 11, bed time! lol I am tired...
    eastern time that is...
     
  2. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    The ram won't help that much. Your right, for 300mhz it is not worth it.
     
  3. edplane

    edplane

    Joined:
    Jul 13, 2009
    Posts:
    485
    Damn, 4 pages? Thats a lot. Say, wht programs do you use for your development? Maybe we can team up and help each other...
     
  4. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    Huh?

    For development I use Unity3d for the game making(DUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUH!!!!!). For modeling... I don't.
    For textures... I don't. Basically, any free model I find, I will use. Same with sounds and textures. I want to know scripting and that is it. I use Unitydevelop for the scripting though, it is waaay better than unity's built in.
     
  5. edplane

    edplane

    Joined:
    Jul 13, 2009
    Posts:
    485
    There are 4 pages to this thread. More than I thought...
    And no DUHHH that you use Unity, probebly thats why your even on the thread, lol
    Yes I meant modeling, I use Cheetah 3D, Its super easy to make characters with..
    and whats so bad about Unity's built in editor? I like it..
     
  6. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    There is a different editor for windows... and it sucks.
    Cheetah3d sounds good.
     
  7. edplane

    edplane

    Joined:
    Jul 13, 2009
    Posts:
    485
    I Know! I personally tried it, and it just dosent feel as good because there are no colors saying that the code is right..
     
  8. Moonlight

    Moonlight

    Joined:
    Jun 7, 2010
    Posts:
    41
    I took this one step further using that last code in my 3rd person shooter and made some changes


    Code (csharp):
    1. var flashlightOn : boolean = false;
    2. var soundOn : AudioClip;
    3. var soundOff : AudioClip;
    4. var whenOn = 5.0;
    5. var whenOff = 0.0;
    6.  
    7.  
    8.  
    9. function Update () {
    10.    //Checks if the boolean is true or false.
    11.    if(flashlightOn == true){
    12.       light.intensity = whenOn;//If the boolean is true, then it sets the intensity to what ever you want.
    13.    } else {
    14.       if(flashlightOn == false){
    15.          light.intensity = whenOff;//If the boolean is false, then it sets the intensity to zero.
    16.       }
    17.    }
    18.    
    19.    //Checks if the F key is down and whether the boolean is on or off.
    20.    if(Input.GetKeyDown(KeyCode.F)  flashlightOn == false){
    21.    
    22.    AudioSource.PlayClipAtPoint(soundOn, light.transform.position);
    23.    flashlightOn = true; //If the f key is down and the boolean is false, it sets the boolean to true.
    24.    
    25.    } else {
    26.    
    27.    if(Input.GetKeyDown(KeyCode.F)  flashlightOn == true) {
    28.    
    29.     AudioSource.PlayClipAtPoint(soundOff, light.transform.position);
    30.     flashlightOn = false;//If the f key is down and the boolean is true, it sets the boolean to false.
    31.       }
    32.    }
    33.    
    34. }

    just put the script onto your light
     

    Attached Files:

  9. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,099
    I know this is an old thread but I figured I would re-post this. I optimized this script to avoid excess checking of booleans. It now adjusts the brightness when the key is pressed and only when the key is pressed. The old code checked every update whether to adjust intensity instead of just when the key was pressed. Very minor but hey, its a few extra lines of code being run every update function ;).

    Code (csharp):
    1.  
    2. var flashlightOn : boolean = false;
    3. var soundOn : AudioClip;
    4. var soundOff : AudioClip;
    5. var onIntensity = 5.0;
    6. var offIntensity = 0.0;
    7.  
    8. function Update () {
    9.    //Checks if the F key is down and whether the boolean is on or off.
    10.    if(Input.GetKeyDown(KeyCode.F)  flashlightOn == false){
    11.    
    12.    AudioSource.PlayClipAtPoint(soundOn, light.transform.position);
    13.    flashlightOn = true; //If the f key is down and the boolean is false, it sets the boolean to true.
    14.    light.intensity = onIntensity;
    15.    
    16.    } else {
    17.    
    18.    if(Input.GetKeyDown(KeyCode.F)  flashlightOn == true) {
    19.    
    20.    AudioSource.PlayClipAtPoint(soundOff, light.transform.position);
    21.    flashlightOn = false;//If the f key is down and the boolean is true, it sets the boolean to false.
    22.    light.intensity = offIntensity;
    23.       }
    24.    }
    25.    
    26. }
    Hmmm found an error where the oneshot audio is not destoryed after playing. Will fix the script and reupload. Sorry for not thoroughly testing. :\

    Edit: Edit: Seems to work fine with audio, if you do not have a sound file selected the audio will be created and not destroyed. Sorry for the confusion. The script works fine now! :)
     

    Attached Files:

  10. Moonlight

    Moonlight

    Joined:
    Jun 7, 2010
    Posts:
    41
    ya, I like that a little better.
     
  11. nevaran

    nevaran

    Joined:
    May 21, 2010
    Posts:
    247
    well i got the flahslight to work....a bit wired but, yeh... 8) 8) :wink:
     

    Attached Files:

  12. TJG10

    TJG10

    Joined:
    Apr 23, 2013
    Posts:
    13
    Wow your flashlight script worked your script can be used for my slenderman survival game but will you put the sound for your flashlight script?
     
  13. Ruben_Chris

    Ruben_Chris

    Joined:
    Mar 10, 2013
    Posts:
    94
    Last edited: Dec 21, 2013