OnCollideSound

From Unify Community Wiki
Revision as of 05:33, 21 September 2008 by Opless (Talk | contribs)

Jump to: navigation, search


Author: Opless

Description

Simple Prefab spawning collision, great for collision sounds

CSharp - OnCollideSound.cs

<csharp> 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; } } } </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox