The enemy that spawn into my game from the Prefab folder does not shoot at the player, but where the player spawns.
//enemy shooting script
var projectile: Rigidbody;
var speed = 25;
var player : Transform;
function Start() {
var rendum = Random.Range(1F,3F);
InvokeRepeating("Shuut", 2, rendum);
}
function Update() {
transform.LookAt(player);
}
function Shuut () {
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
Destroy (clone.gameObject, 50);
}
//enemy movement script
var startMarker: Transform;
var endMarker: Transform;
// Movement speed in units/sec.
var speed = 10.0;
// Time when the movement started.
private var startTime: float;
// Total distance between the markers.
private var journeyLength: float;
var target : Transform;
var smooth = 5.0;
function Start() {
// Keep a note of the time the movement started.
startTime = Time.time;
// Calculate the journey length.
journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
}
// Follows the target position like with a spring
function Update () {
// Distance moved = time * speed.
var distCovered = (Time.time - startTime) * speed;
// Fraction of journey completed = current distance divided by total distance.
var fracJourney = distCovered / journeyLength;
transform.position=Vector3.Lerp(startMarker.position, endMarker.position, Mathf.PingPong(Time.time*speed, 1.0f));
}