Right to the case im trying to get som interval between my footsteps, my current script is not working.
void Update ()
{
float vel = tpcontroller.characterController.velocity.magnitude;
RaycastHit hit;
string floorTag;
if (tpcontroller.characterController.isGrounded && vel > 0.2f) {
if (Physics.Raycast (transform.position, Vector3.down, out hit)) {
floorTag = hit.collider.gameObject.tag;
if (floorTag == "Wood") {
audio.clip = woodStep;
} else if (floorTag == "Water") {
audio.clip = waterStep;
} else if (floorTag == "Metal") {
audio.clip = metalStep;
} else if (floorTag == "Terrain") {
// check texture and get correct clip
int t = GetMainTexture (transform.position);
if (t == 0) {
// grass
audio.clip = grassStep;
} else if (t == 1) {
} else if (t == 2) {
} else if (t == 3) {
} else if (t == 4) {
} else if (t == 5) {
} else if (t == 6) {
} else if (t == 7) {
} else if (t == 8) {
// dirt
audio.clip = dirtStep;
}
}
StartCoroutine (Footsteps ());
// Play the correct sound
audio.PlayOneShot (audio.clip);
} else {
}
}
}
IEnumerator Footsteps ()
{
if (tpanimator.isRunning) {
yield return new WaitForSeconds (runningInterval);
} else if (tpanimator.isCrouching) {
yield return new WaitForSeconds (crouchingInterval);
} else {
yield return new WaitForSeconds (walkingInterval);
}
}
↧