Question by
Samflournoy · Mar 23, 2016 at 12:59 PM ·
particle systemcollisions
Particle system works on one object, but not duplicate??
I am making a simple iphone game where the user is controlling a car. When the car hits a tree, I am attempting to:
Stop rendering the tree
Play the particle system (mimic's tree exploding)
Destroy tree after 1 second
My code was working fine, but when I attempted to duplicate the tree, the particle system plays (upon collision) intermittently, and only for the original tree. Any advice?? using UnityEngine; using System.Collections;
public class colUpdate : MonoBehaviour {
public float timeSince = 0f;
//GameObject player = GameObject.Find ("Player");
carMove carScript;
// Use this for initialization
void Start () {
GameObject player = GameObject.Find ("Player");
carScript = player.GetComponent<carMove> ();
}
// Update is called once per frame
void Update () {
timeSince += Time.deltaTime;
}
void OnTriggerEnter (Collider col) {
//Car hits tree
if (col.gameObject.name.Contains("tree")) {
GameObject thisTree = GameObject.Find (col.gameObject.name);
MeshRenderer rend = thisTree.GetComponent<MeshRenderer> ();
ParticleSystem ps = thisTree.GetComponent<ParticleSystem> ();
//Plays particle system
ps.Play ();
//Makes tree disappear
rend.enabled = false;
Destroy (col.gameObject, 1);
}
//Car on road
if (col.gameObject.name == "OnRoad") {
carScript.maxSpeed = 0.3f;
carScript.accel = 0.01f;
}
Debug.Log ("Working!: " + col.gameObject.name);
timeSince = 0f;
}
//Car off road
void OnTriggerExit (Collider col){
if (col.gameObject.name == "OnRoad") {
carScript.maxSpeed = carScript.grassSpeed;
carScript.accel = -0.01f;
}
}
}
Comment