i need some help modify some c# code ive got everything else down i just need this little part to fix (hopefully) any help? everything ive seen doesnt explain really how to fix the problem.
using UnityEngine;
using System.Collections;
public class Ballcontrol : MonoBehaviour {
public int rotationSpeed= 100;
public int jumpHeight= 8;
private bool playOnce= true;
public AudioClip Hit01;
public AudioClip Hit02;
public AudioClip Hit03;
private bool isFalling= false;
void Update (){
//Handle ball rotation.
float rotation = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.back * rotation);
if (Input.GetKeyDown(KeyCode.W) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
playOnceTrue();
}
isFalling = true;
}
void OnCollisionStay (){
if (playOnce == true)
{
int theHit= Random.Range(0, 4);
if (theHit == 0)
{
audio.clip = Hit01;
}
else if (theHit == 1)
{
audio.clip = Hit02;
}
else {
audio.clip = Hit03;
}
audio.pitch = Random.Range (0.9f,1.1f);
audio.Play();
playOnce = false;
}
isFalling = false;
}
IEnumerator playOnceTrue (){
yield return new WaitForSeconds (0.2f);
playOnce = true;
}
}
↧