Why Trail Renderer and A Basic Script Stops Working?
Hi, Sometimes in my game trail renderer of specific object and a specific script stops working at the same time without a reason. Object is my player's bullets, contains a Rigidbody2D, Box Collider (as trigger) and two scripts. Scripts are:
using UnityEngine;
using System.Collections;
public class PlayerBullet : MonoBehaviour {
Transform player;
void Awake() {
player = GameObject.FindGameObjectWithTag ("Player").GetComponent<Transform>();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Vector3.Distance (player.position, transform.position) > 10) {
Destroy (gameObject);
}
}
void OnTriggerEnter2D(Collider2D other) {
if (other.tag == "Player" || other.tag == "PlayerBullet" || other.tag.Contains ("Pickup") ||
other.tag == "Explosion") {
return;
} else if (other.tag == "ProtoZero") {
other.GetComponent<ProtoZero> ().damageMe (10);
Destroy (gameObject);
} else if (other.tag == "ProtoOne") {
other.GetComponent<ProtoOne> ().damageMe (10);
Destroy (gameObject);
} else if (other.tag == "ProtoTwo") {
other.GetComponent<ProtoTwo> ().damageMe (10);
Destroy (gameObject);
} else {
Destroy (gameObject);
}
}
}
and
using UnityEngine;
using System.Collections;
public class BulletDestroy : MonoBehaviour {
public Transform explosion;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnDestroy() {
Transform newExplo = Instantiate (explosion);
newExplo.position = transform.position;
Destroy (newExplo.gameObject, 1f);
}
}
That simple script stops working also:
using UnityEngine;
using System.Collections;
public class PickupShake : MonoBehaviour {
int direction = 1;
float firstY;
// Use this for initialization
void Start () {
firstY = transform.position.y;
}
// Update is called once per frame
void Update () {
if (Mathf.Abs (transform.position.y - firstY) >= 0.05f)
direction *= -1;
transform.position += new Vector3 (0, direction * 0.2f * Time.deltaTime, 0);
}
}
I can't figure out what is the problem. Thanks for your help in advance!
asdasdasqwe.png
(47.3 kB)
Comment
Not 100% sure what the actual problem is. Seems to be an awful amount of "Destroy(gameObject)" which I assume is destroying the bullet and trail render.