I’m trying to make an object move when my projectile hits it. I have it so the bullet disappears when it hits something else and I’ve attached the following script to the prefab which i’m having trouble with. Basically, the prefab is called EvilPlant and it has animation, and instantiates every so often (minimum 1 second, maximum 2 seconds) I tried making the prefab destroy when its hit by the bullet but then they don’t spawn anymore because they delete automatically eventually. So i’ve made it so it just moves the prefab out of the screen but now they spawn a couple of times but eventually they stop again
using UnityEngine;
using System.Collections;
public class PlantMover : MonoBehaviour {
public float minSpawnTime = 1.0f;
void OnTriggerEnter2D(Collider2D other) {
if (gameObject.name.StartsWith("EvilPlant")) {
transform.position = new Vector3(0,-10,0);
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}