game Object not play sound if object moved

Helllo help me pls here is script

  void Update()
    {
       

        rigidbody.velocity = new Vector3(transform.position.x, transform.position.y, transform.position.z);

        if (rigidbody.velocity.magnitude > 0.1)
        {
            move.Play();
        }
        else

            move.Pause();

}

What do you want to happen?
What is happening instead?

You said “game Object not play sound if object moved”. Is that what’s happening and you want something else to happen? Is something else happening but you want that to happen instead? Please clarify.

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

How to understand errors in general:

https://discussions.unity.com/t/824586/8

here is new script but my sound played not good why pls

    void FixedUpdate()
    {
        speed = (transform.position - lastPosition).magnitude;
        lastPosition = transform.position;
       
        if (speed > 0.01)
        {
            move.PlayOneShot(moveclip);

        }
        else
            move.Pause();
    }

I don’t think we’re making progress here. Please carefully read the link I provided above.

No one but yourself has any idea what “not good” sound means in this context.

A quick guess though, it looks like while your object is moving it will start playing the same audio clip every fixedupdate. I’m guessing what you really want is to just keep repeating the same audio while moving, but not restart it from the beginning 50x a second (I forget the behavior of PlayOneShot if it is already in the middle of playing the same clip you are telling it to play again, but I’m guessing it is not what you want) If that is the case, redesign so you start playing it once, then just check if it is still playing. If not playing anymore (means the audio clip has reached its end), then start playing it again. If still playing then do nothing.

1 Like

Thanks bug fixed

void FixedUpdate()
    {
        speed = (transform.position - lastPosition).magnitude;
        lastPosition = transform.position;
       
        if (speed > 0.01)
        {

            if (!move.isPlaying)
            {
                move.Play();
           
            }

        }
        else
            move.Pause();
          
    }