Search Unity

Incorrect Tutorials?

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

  1. KlaRo115

    KlaRo115

    Joined:
    Feb 24, 2006
    Posts:
    675
    Hi, today I tried to write a script that plays a sound when you push a button and stops it when you stop pushing that button... :)

    The problem is that the function "AudioSource.Stop" seems to be an incorrect expression, but I found it on http://unity3d.com/support/documentation/ScriptReference/AudioSource.Stop.html ...

    So, I think that there could be some older expressions that aren't used in unity anymore... :?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, it works fine. Anything that's in the current docs works.

    --Eric
     
  3. KlaRo115

    KlaRo115

    Joined:
    Feb 24, 2006
    Posts:
    675
    :eek:
    ...
    But when I used it in my code, there was written:

    Code (csharp):
    1. var speed = 2.5;
    2. var openSpeed = 2.5;
    3. var useTime = 6.0;
    4. var fallSpeed = 1.0;
    5. var useKey : String;
    6. var wheel : Transform;
    7. var rotate : boolean = true;
    8. var door : Transform;
    9. var openDoor : boolean = true;
    10. var fall : boolean = false;
    11. var wheelSound : AudioClip;
    12. var playSound : boolean = true;
    13. var doorStart : Transform;
    14. var doorEnd : Transform;
    15.  
    16. function OnTriggerStay () {
    17.     if (Input.GetKey (useKey)) {
    18.         if (rotate == true) {
    19.             wheel.Rotate (0, speed, 0);
    20.             }
    21.         if (openDoor == true) {
    22.             door.Translate (0, openSpeed, 0);
    23.             }
    24.         }
    25.         if (door.transform.position.y >= doorEnd.transform.position.y) {
    26.             openDoor = false;
    27.             }
    28.     if (Input.GetKeyDown (useKey)) {
    29.         if (rotate == true) {
    30.             if (playSound == true) {
    31.                 AudioSource.PlayClipAtPoint (wheelSound, transform.position);
    32.                 playSound = false;
    33.             }
    34.         }
    35.     }
    36.     if (Input.GetKeyUp (useKey)) {
    37.         audio.Stop;
    38.         }
    39.     }
    40.  
    41. function OnTriggerExit () {
    42.         fall = true;
    43.         opendoor = false;
    44.         playSound = true;
    45.         Update ();
    46.     }
    47.  
    48. function Update () {
    49.     if (fall == true) {
    50.         door.transform.Translate(0, -fallSpeed, 0 * Time.deltaTime);
    51.         }
    52.     if (door.transform.position.y <= doorStart.transform.position.y) {
    53.         openDoor = true;
    54.         fall = false;
    55.         }
    56.     }
    57.  
    58.                
    59. @script RequireComponent (AudioSource)
     

    Attached Files:

  4. GargerathSunman

    GargerathSunman

    Joined:
    May 1, 2008
    Posts:
    1,571
    Try doing this: audio.Stop()

    The parenthesis are a requirement for ALL functions. ^_^
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I feel compelled to point out that the sample code in the docs says "audio.Stop()"...always pay attention to the docs....

    --Eric
     
  6. KlaRo115

    KlaRo115

    Joined:
    Feb 24, 2006
    Posts:
    675
    Sorry, I red quickly over the tutorial, so I didn't see this... :oops: