Game Bucks

Object Impact Sound

This is a really simple, but effective script to add to your game. When an object with a collider hits another collider, it plays a sound. The volume is correlated to how hard it hits a object. Use without credits because it is not necessary.

MAKE A C# SCRIPT AND NAME IT “ImpactEffect”

using UnityEngine;
using System.Collections;
 
[RequireComponent(typeof(AudioSource), typeof(Rigidbody))]
public class ImpactEffect: MonoBehaviour {
        public AudioClip impactSound;
        public float impactAudioModifier = 1.0f; //Modifies how loud the audio plays related to how hard it hits
 
        void OnCollisionEnter(Collision col) {
                audio.PlayOneShot(impactSound, col.relativeVelocity.magnitude * 0.1f * impactAudioModifier);
        }
}

Game Bucks

Add comment

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.