I’m doing a tornado effect with the objects having this script on move towards the tornado, then bounce back out of the tornado and destroy.
public static bool isClose = false;
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Tornado") {
isClose = true;
GetComponent<Rigidbody> ().AddRelativeForce (Random.onUnitSphere * 500);
Debug.Log ("isClose = True");
StartCoroutine ("Death");
//Explosion ();
}
}
public IEnumerator Death()
{
yield return new WaitForSeconds (3);
isClose = false;
Destroy (this.gameObject);
}
For now I just use a AddRelativeForce to make it bounce out of the tornado to a random direction.
If I remove the Destroy line in my Death to keep my objects and just let them fall to the ground, They all move in a weird way. It’s like all the objects with this script attached stop moving towards the tornado when isClose becomes true, but I want every object with this script to have it’s own isClose attribute.
Here’s what I have in my tornado script:
private GameObject PullOBJ;
public float PullSpeed;
public void OnTriggerStay(Collider coll)
{
if (coll.gameObject.tag == "Pullable") {
PullOBJ = coll.gameObject;
if (PullObject.isClose == false) {
PullOBJ.transform.position = Vector3.MoveTowards (PullOBJ.transform.position, this.transform.position, PullSpeed * Time.deltaTime);
}
}
}
How can I do that?
It makes sense for 1 object, but if I have a couple of them with the same PullObject script on, they all move / stop moving together…