- Home /
Question by
PeCcHy · Nov 04, 2016 at 08:32 AM ·
javascriptphysicsaudiomovement scriptaudio.clip
I can't make my ball jump using distToGround and Physics.Raycast
I'm new and I don't understand this. Here is the script that I'm trying to make the ball jump on :
#pragma strict
var rotationSpeed = 100;
var jumpHeight = 8;
var speed : float = 0.2;
var TurnSpeed : float = 2.0;
public static var distToGround = GetComponent.<Collider>().bounds.extents.y;
var distanceToGround = distToGround;
var Hit01 : AudioClip;
var Hit02 : AudioClip;
var Hit03 : AudioClip;
private var isFalling = false;
function IsGrounded () : boolean {
return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1);
}
function Update () {
//Handle ball rotation
var rotation : float = Input.GetAxis ("Vertical") * rotationSpeed;
rotation *= Time.deltaTime;
GetComponent.<Rigidbody>().AddTorque (Vector3.back * rotation * 50);
var rotation2 : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation2 *= Time.deltaTime;
GetComponent.<Rigidbody>().AddTorque (Vector3.left * rotation2 * 50);
//jump
if (Input.GetKeyDown(KeyCode.Space) && IsGrounded() ) {
GetComponent.<Rigidbody>().velocity.y = jumpHeight;
}
isFalling = true;
}
function OnCollisionStay () {
isFalling = false;
}
function OnCollisionEnter () {
var theHit = Random.Range(0, 3);
if (theHit == 0){
var audio: AudioSource = GetComponent.<AudioSource>();
audio.clip = Hit01;
}
else if ( theHit == 1){
var audio2: AudioSource = GetComponent.<AudioSource>();
audio.clip = Hit02;
}
else {
var audio3: AudioSource = GetComponent.<AudioSource>();
audio.clip = Hit03;
}
audio.pitch = Random.Range(0.9, 1.1);
audio.Play();
}
The error I get is
InvalidProgramException: Invalid IL code in BallControl:.cctor (): IL_0000: ldarg.0 Rethrow as TypeInitializationException: An exception was thrown by the type initializer for BallControl
And whenever I start the game I can't move or jump. If i change the y of the Ball and let it fall i can't hear anything either.What should I do?
Comment