Generation

generate functionMon, 05 Dec 2022

if the obiect with the tag "Player" is moving play sound Footstep.wav sequientially with the cadence of it's trasform velocity

using UnityEngine; using System.Collections; public class AudioPlay : MonoBehaviour { public GameObject player; public AudioClip[] footStep; public float stepDistance = 0.25f; public float stepVolume = 0.5f; public float stepPitch = 1.0f; float nextStep = 0; float stepInterval = 0.5f; void Update() { if (player.transform.position.magnitude > nextStep) { AudioClip clip = footStep[Random.Range(0, footStep.Length)]; AudioSource.PlayClipAtPoint(clip, transform.position, stepVolume); nextStep = player.transform.position.magnitude + stepDistance; stepInterval = clip.length / stepPitch; } } }

Questions about programming?Chat with your personal AI assistant