No way I can make my PlayOneShot work with the sounds. The only way I can make the sound work is if I use the audio on AudioSource ( Which I can use only one sound). I tried to check the volume, is not the case. I used Debug.Log to check if Stop sound is overcoming PlayOneSound (is not the case). I desactivated the collision Script to see if there is anything cause trouble (not the case). Tried different audios, checked if my Unity is without sound (no the case because if I use mainEngine on AudioSource component it works just fine. Any more Ideas on what I can try?? I will Skip this lesson for now since I have been breaking my head with this for days!
This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Movement : MonoBehaviour
{
Rigidbody Rb;
AudioSource audioSource;
public AudioClip mainEngine;public float thrustSpeed = 1000.0f; private float rotationThrust = 100.0f; void Start() { Rb = GetComponent<Rigidbody>(); audioSource = GetComponent<AudioSource>(); } void Update() { ProcessThrust(); ProcessRotation(); } void ProcessThrust() { if (Input.GetKey(KeyCode.UpArrow)) { Rb.AddRelativeForce(Vector3.up * Time.deltaTime * thrustSpeed); if (!audioSource.isPlaying) { Debug.Log("Audio Playing"); audioSource.PlayOneShot(mainEngine, 1.0f); } } else { Debug.Log("Audio Not playing"); audioSource.PlayOneShot(mainEngine, 1.0f); } } void ProcessRotation() { if (Input.GetKey(KeyCode.LeftArrow)) { applyRotation(rotationThrust); } if (Input.GetKey(KeyCode.RightArrow)) { applyRotation(-rotationThrust); } } private void applyRotation(float rotateThisFrame) { Rb.freezeRotation = true; // stops rigidbody rotation to act while player is turning rotation, this fix bug about colission when rocket collides the control gets crazy transform.Rotate(Vector3.forward * Time.deltaTime * rotateThisFrame); Rb.freezeRotation = false; // after player is not using command to rotate anymore, it returns to the normal }
}
This is the SS of unity: