Je suis entrain de faire un script qui consiste à jouer un sons de pas toute les 0,3 secondes en fonction du type de sol. Le problème, c'est qu'une fois en jeu, ca ne fonctionne pas, et j'ai du mal à cerner le problème: Il n'y a aucune erreur dans la console, malgré que le jeu tourne. J'ai également assimilé les sons dans l'inspector. Voici le script:
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
public class playAudioScript2 : MonoBehaviour {
public AudioClip herbe;
public AudioClip beton;
public AudioClip feuille;
public AudioSource source;
Collider2D collider;
public int index = 0;
private KeyCode[] Fleche = { KeyCode.LeftArrow, KeyCode.RightArrow, KeyCode.Q, KeyCode.D };
void Awake () {
source = GetComponent<AudioSource>();
collider = GetComponent<CapsuleCollider2D> ();
}
void OnTriggerEnter2D (Collider2D other) {
if (Input.GetKeyDown(Fleche[index])){
if (other.tag == "Herbe") {
PlayTheSoundHerbe ();
} else if (other.tag == "Beton") {
PlayTheSoundBeton ();
} else if (other.tag == "Feuille") {
PlayTheSoundFeuille ();
}
}
}
void PlayTheSoundHerbe() {
source.PlayOneShot(herbe);
InvokeRepeating ("PlayTheSoundHerbe", 0f, 0.3f);
}
void PlayTheSoundBeton() {
source.PlayOneShot(beton);
InvokeRepeating ("PlayTheSoundBeton", 0f, 0.3f);
}
void PlayTheSoundFeuille(){
source.PlayOneShot (feuille);
InvokeRepeating ("PlayTheSoundFeuille", 0f, 0.3f);
}
void Update () {
}
}