Audio source project boost

Hey guys i really need help with this audio source the rocket audio stay repetitive like in this video https://youtu.be/Tc1eQja4ap4
and the script

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rocket : MonoBehaviour
{
Rigidbody rigidBody;
AudioSource audioSource;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent();
audioSource = GetComponent();
}

// Update is called once per frame
void Update()
{
    ProcessInput();
}

private void ProcessInput()
{
    if (Input.GetKey(KeyCode.Space))
    { 
        print("Empurrando");
        rigidBody.AddRelativeForce(Vector3.up);
        if (audioSource.isPlaying == false){
            audioSource.Play();
        }
        else 
        { 
            audioSource.Stop(); 
        }
    }
   

    if (Input.GetKey(KeyCode.A))
    { print("Rotate Left");
        transform.Rotate(-Vector3.forward);
      
    }

    else if (Input.GetKey(KeyCode.D))
    { print("Rotate Right");
        transform.Rotate(Vector3.forward);
    }
}

}

@Fernandeeess Why don’t you set it to loop in the inspector and then stop it and play it at your will. You don’t have to write the code for isPlaying and all…

Your code appears to be starting and stopping the sound every frame when the space key is pressed.

Try this …

Replace

if (Input.GetKey(KeyCode.Space))
    { 
        print("Empurrando");
        rigidBody.AddRelativeForce(Vector3.up);
        if (audioSource.isPlaying == false){
            audioSource.Play();
        }
        else 
        { 
            audioSource.Stop(); 
        }
    }

with

if (Input.GetKey(KeyCode.Space))
    { 
        print("Empurrando");
        rigidBody.AddRelativeForce(Vector3.up);
        if (audioSource.isPlaying == false){
            audioSource.Play();
        }
     
    }
   else{
        if (audioSource.isPlaying){
            audioSource.Stop(); 
        }     
   }

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms