- Home /
Enemy Seeking Missiles
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BulletTrial : MonoBehaviour {
public int Speed = 2;
public float LifeSpan = 3f;
public Transform Target;
void OnTriggerEnter2D( Collider2D Enemy)
{
if (Enemy.tag == "Biter") {
Destroy (this.gameObject);
}
if (Enemy.tag == "Brawler") {
Destroy (this.gameObject);
}
}
void FixedUpdate() {
transform.LookAt(Target);
transform.Translate(Vector3.forward*Speed*Time.deltaTime);
transform.Translate (Vector3.right * Time.deltaTime * Speed);
Destroy (this.gameObject, LifeSpan);
}
}
What It Does
Spawns Missile on click at weapon point,
Missile seeks out ORIGINAL position of game object with tag (Enemy) prefab,
Destroys enemy and rocket,
All future instantiated Rockets head to same location regardless if enemy is there of not
What I am trying to do
Spawns Missile on click at weapon point,
Missile seeks out position of NEAREST game object with tag (Enemy) prefab,
Destroys enemy and rocket,
4.All future instantiated Rockets search and head to the NEAREST game object tagged enemy.
i have looked for the past couple days for a solution and tried many many different types of codes varieties. i wouldn't be asking this if i hadn't tried to fix it myself already.
I've been using unity for about a month and hoping to reach out to this community more in the future. Thanks in advance.