OnCollideSound

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
m (Text replace - "</javascript>" to "</syntaxhighlight>")
 
Line 49: Line 49:
 
}
 
}
 
}
 
}
</javascript>
+
</syntaxhighlight>

Latest revision as of 20:52, 10 January 2012

Author: Opless

[edit] Description

Simple Prefab spawning collision, great for collision sounds

[edit] 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;
		}	
	}
}

[edit] 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