Hello, I was writing a program in javascript when I got the error in the title. Here is my program. It is a simple, controllable ball that makes a noise when it hits the ground.
Here is my code.
#pragma strict
var rotationSpeed = 100;
var jumpHeight = 8;
private var SoundOnce = true;
private var isFalling = false;
var Hit01 : AudioClip;
var Hit02 : AudioClip;
var Hit03 : AudioClip;
function Update ()
{
//Handle ball rotation.
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
GetComponent.<Rigidbody>().AddRelativeTorque (Vector3.back * rotation);
//Handle ball jump.
if (Input.GetKeyDown(KeyCode.W) && isFalling == false)
{
GetComponent.<Rigidbody>().velocity.y = jumpHeight;
SoundOnceTrue();
}
isFalling = true;
}
function OnCollisionStay ()
{
if (SoundOnce == true)
{
var theHit = Random.Range(0, 4);
if (theHit == 0) {
GetComponent.<AudioSource>().clip = Hit01;
}
else if (theHit == 1) {
GetComponent.<AudioSource>().clip = Hit02;
}
else {
GetComponent.<AudioSource>().clip = Hit03;
}
GetComponent.<AudioSource>().Play;
SoundOnce = false;
}
isFalling = false;
}
function SoundOnceTrue () {
yield WaitForSeconds (0.3);
SoundOnce = true;
}
The compiler says the error is on this line, and this is what gets me.
GetComponent.<AudioSource>().Play;
I don’t understand why the error happens when the noise is played. The error is caused by code that doesn’t do anything right?