I am trying to play a audio when an object is destroyed the only problem with that is when I click "Play on Active" It just keeps playing every time the object is spawned. One way I was able to fix this was through turning off "Is Trigger". But when I do that the object just floats away. I do have tumble on it. I do not know if the code or something for it is messed up but here are all the scripts I have attached to it.
Random Rotator
using UnityEngine;
using System.Collections;
public class RandomRotator : MonoBehaviour
{
public float tumble;
void Start ()
{
rigidbody.angularVelocity = Random.insideUnitSphere * tumble;
}
}
Destroy By Contact
using UnityEngine;
using System.Collections;
public class DestroyByContact : MonoBehaviour
{
public GameObject explosion;
public GameObject playerExplosion;
void OnTriggerEnter(Collider other) {
if (other.tag == "Boundary") {
return;
}
Destroy (other.gameObject);
Destroy (gameObject);
Instantiate (explosion, transform.position, transform.rotation);
if (other.tag == "Player") {
Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
}
}
}
Mover
using UnityEngine;
using System.Collections;
public class Mover : MonoBehaviour
{
public float speed;
void Start ()
{
rigidbody.velocity = transform.forward * speed;
}
}
↧