OnCollideSound

From Unify Community Wiki
Jump to: navigation, search

Author: Opless

Description

Simple Prefab spawning collision, great for collision sounds

CSharp - OnCollideSound.cs

using UnityEngine;
 
public class OnCollideSound : MonoBehaviour 
{
	public GameObject collisionSoundPrefab;
	public float      triggerMagnitude = 2;
	public bool       attachToMe = true;
 
	void OnCollisionEnter( Collision collision ) 
	{
		if (collision.relativeVelocity.magnitude > triggerMagnitude)
		{
			GameObject o = (GameObject) Instantiate(collisionSoundPrefab, this.transform.position, this.transform.rotation);
			if(attachToMe)
				o.transform.parent = transform;
		}	
	}
}

Javascript - OnCollideSound.js

var collisionSoundPrefab : GameObject;
var triggerMagnitude : float = 2;
var attachToMe : boolean = true;
 
function OnCollisionEnter( collision : Collision ) 
{
	if (collision.relativeVelocity.magnitude > triggerMagnitude)
	{
		var o : GameObject = Instantiate(collisionSoundPrefab, this.transform.position, this.transform.rotation);
		if(attachToMe) {
			o.transform.parent = transform;
		}	
	}
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox