Question by
ROMAINSEIN · Mar 03, 2019 at 07:05 PM ·
sound effects
Sound on moving an object
Hi! I' am total beginner and i mostly copy and paste scripts to make things work ( also I'm french so sorry broken for the English).
I guess it's really simple, i have a FPS character that can move objects,I need them to make a sound (like a Rolling ball sound for exemple) when I move them, pushing them... I tried to use a script that play sound on collision but the result is too weird.
Here is the script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CollisionSound : MonoBehaviour
{
//volume: 0..1
//Magnitude
private void OnCollisionStay(Collision collision)
{
GetComponent<AudioSource>().Play();
}
}
If someone as Something i'll be really Gratefull !
untitled-1.jpg
(141.9 kB)
Comment
Answer by xxmariofer · Mar 03, 2019 at 08:13 PM
change the oncollisitionstay to OnCollisionEnter, oncollisionstay is being called every fixed frame so you are playing over and over and over the same clip (a lot of times persecond)
Yes! It's so perfect now. $$anonymous$$erci infiniment!