Search Unity

Audio.PlayOneShot-Problem

Discussion in 'Scripting' started by KlaRo115, Sep 20, 2008.

  1. KlaRo115

    KlaRo115

    Joined:
    Feb 24, 2006
    Posts:
    675
    hello community, I have another problem with one of my new codes:
    I want a script to play a sound only the time I hold a special button, but I don't exactly know, which word to use, at the moment, that's my script:

    Code (csharp):
    1. var speed = 2.5;
    2. var openSpeed = 2.5;
    3. var useTime = 6.0;
    4. var useKey : String;
    5. var wheel : Transform;
    6. var rotate : boolean = true;
    7. var door : Transform;
    8. var openDoor : boolean = true;
    9. var wheelSound : AudioClip;
    10.  
    11. function OnTriggerStay () {
    12.     if (Input.GetKey (useKey)) {
    13.         if (rotate == true) {
    14.             wheel.Rotate (0, speed, 0);
    15.             audio.PlayOneShot (wheelSound, 0.5);
    16.             }
    17.         if (openDoor == true) {
    18.             door.Translate (0, openSpeed, 0);
    19.             Invoke ("StopDoor", useTime);
    20.             }
    21.         }
    22.     }
    23.  
    24. function StopDoor () {
    25.     openDoor = false;
    26.     }
    27.    
    28. @script RequireComponent (AudioSource)