Question by
saadbitar98 · Jun 18, 2016 at 11:55 AM ·
audioclip
i need your help
im trying to add a sound to my game. when i hit the ball on the groung i should get a sound here is my code in javascript : #pragma strict
var rotationSpeed = 100;
var jumpHeight = 8;
var playOnce = true;
var Hit01 : AudioClip;
private var isFalling = false;
function Update ()
{
//Handle ball rotation
var rotation : float= Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
GetComponent.<Rigidbody>().AddRelativeTorque (Vector3.back * rotation);
if (Input.GetKeyDown (KeyCode.JoystickButton2) && isFalling == false)
{
GetComponent.<Rigidbody>().velocity.y = jumpHeight;
playOnceTrue();
}
isFalling = true;
}
function OnCollisionStay ()
{
if (playOnce == true);
{
var theHit = Random.Range(0,4);
if (theHit == 0)
{var audio: AudioSource = GetComponent.<AudioSource>();
audio.clip = Hit01;
audio.Play();}
}
}
function playOncetrue ()
{
yield WaitForSeconds(0.2);
playOnce = true;
}
im getting a BCE0005: Unknown identifier: 'playOnceTrue' error what should i do ? plzz help
Comment
Answer by mwnDK1402 · Jun 18, 2016 at 02:27 PM
You are trying to call a function named "playerOnceTrue", but no such function exists. Rename "playOncetrue" to "playOnceTrue".
EDIT: I'm not very familiar with JavaScript, so I'm not sure if there are any other problems apart from what I've pointed out.
Your answer