Incorrect Tutorials?

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… :slight_smile:

The problem is that the function “AudioSource.Stop” seems to be an incorrect expression, but I found it on Unity - Scripting API: AudioSource.Stop

So, I think that there could be some older expressions that aren’t used in unity anymore… :?

No, it works fine. Anything that’s in the current docs works.

–Eric

:shock:

But when I used it in my code, there was written:

var speed = 2.5;
var openSpeed = 2.5;
var useTime = 6.0;
var fallSpeed = 1.0;
var useKey : String;
var wheel : Transform;
var rotate : boolean = true;
var door : Transform;
var openDoor : boolean = true;
var fall : boolean = false;
var wheelSound : AudioClip;
var playSound : boolean = true;
var doorStart : Transform;
var doorEnd : Transform;

function OnTriggerStay () {
	if (Input.GetKey (useKey)) {
		if (rotate == true) {
			wheel.Rotate (0, speed, 0);
			}
		if (openDoor == true) {
			door.Translate (0, openSpeed, 0);
			}
		}
		if (door.transform.position.y >= doorEnd.transform.position.y) {
			openDoor = false;
			}
	if (Input.GetKeyDown (useKey)) {
		if (rotate == true) {
	  		if (playSound == true) {
	  			AudioSource.PlayClipAtPoint (wheelSound, transform.position);
	  			playSound = false;
			}
		}
	}
	if (Input.GetKeyUp (useKey)) {
		audio.Stop;
		}
	}

function OnTriggerExit () {
		fall = true;
		opendoor = false;
		playSound = true;
		Update ();
	}

function Update () {
	if (fall == true) {
		door.transform.Translate(0, -fallSpeed, 0 * Time.deltaTime);
		}
	if (door.transform.position.y <= doorStart.transform.position.y) {
		openDoor = true;
		fall = false;
		}
	}

				
@script RequireComponent (AudioSource)

Try doing this: audio.Stop()

The parenthesis are a requirement for ALL functions. :slight_smile:

I feel compelled to point out that the sample code in the docs says “audio.Stop()”…always pay attention to the docs…

–Eric

Sorry, I red quickly over the tutorial, so I didn’t see this… :sweat_smile: