dodaj do tego skyptu by gdy ciagle jest trzymany przycisk czyli ciagle jest chodzenie…
- User
dodaj do tego skyptu by gdy ciagle jest trzymany przycisk czyli ciagle jest chodzenie lub bieganie niech zmienia ciagle klip po kazdym kolejnym (input W itp) nie zmieniaj reszty using System.Collections; using UnityEngine;
public class Footsteps : MonoBehaviour { public AudioSource footstepsSource; public AudioSource sprintSource; public AudioClip[] footstepClips; public AudioClip[] sprintClips;
private int currentFootstepIndex = 0; private int currentSprintIndex = 0; void Update() { if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D)) { if (Input.GetKey(KeyCode.LeftShift)) { PlaySprintSound(); StopFootstepSound(); } else { PlayFootstepSound(); StopSprintSound(); } } else { StopFootstepSound(); StopSprintSound(); } } private void PlayFootstepSound() { if (!footstepsSource.isPlaying) { footstepsSource.clip = footstepClips[currentFootstepIndex]; footstepsSource.enabled = true; footstepsSource.Play(); StartCoroutine(WaitForFootstepClipToEnd()); } } private void PlaySprintSound() { if (!sprintSource.isPlaying) { sprintSource.clip = sprintClips[currentSprintIndex]; sprintSource.enabled = true; sprintSource.Play(); StartCoroutine(WaitForSprintClipToEnd()); } } private void StopFootstepSound() { if (footstepsSource.isPlaying) { StartCoroutine(DisableAudioSourceAfterPlayback(footstepsSource)); } } private void StopSprintSound() { if (sprintSource.isPlaying) { StartCoroutine(DisableAudioSourceAfterPlayback(sprintSource)); } } private IEnumerator WaitForFootstepClipToEnd() { while (footstepsSource.isPlaying) { yield return null; } currentFootstepIndex = (currentFootstepIndex + 1) % footstepClips.Length; } private IEnumerator WaitForSprintClipToEnd() { while (sprintSource.isPlaying) { yield return null; } currentSprintIndex = (currentSprintIndex + 1) % sprintClips.Length; } private IEnumerator DisableAudioSourceAfterPlayback(AudioSource audioSource) { // Czekaj aż klip przestanie być odtwarzany while (audioSource.isPlaying) { yield return null; } // Wyłącz AudioSource audioSource.enabled = false; }}
- Assistant
- User
zrób tak by jedenj dzwiek odpalał się a kolejny dopiero po zakonczeniu poprzedniego
- Assistant
- User
zrób także tak że jak przycisk zostanie klikniety to odpala sie juz dzwiek poruszania, tylko jeden klip oczywiscie
- Assistant
- User
spraw by pojedyncze klikniecie Inputu uruchamiało dzwięk az do końca dziweku
- Assistant
- User
ale także dodaj że ciągle przytrzymanie klawisza sprawia że dzwięk idzie dalej
- Assistant
- User
spraw by pojedyncze klikniecie musiało trwać przynajmiej pół sekundy by uruchomił się dzwięk
- Assistant