Hey guys.
. What I'm attempting to do (and having little success with) is to sort the script so that when the enemy is at for example equal to a certain point i.e: -3 in the .y axis a bullet is fired.
If anyone knows the best way of doing this then I would greatly appreciate it, I'm loving unity and I'm learning quite quick, however in this case I'm confused as to why if position == (insert number here) doesn't appear to work, clearly the enemy has to cross y.3 in order to reach .y 6 for example.
Right now the script is written so that if the enemy is below a certain point then he will stop, and if his STOP position is equal to what I want then he will fire. I'm assuming that if position.y == doesn't work because the enemy is moving too fast, however I would like to get around this problem without slowing the enemy movement down.
Currently My enemy script is as follows
using UnityEngine;
using System.Collections;
public class Enemy_Script : MonoBehaviour
{
public float MinSpeed;
public float MaxSpeed;
public float currentSpeed;
private float x, y, z;
public GameObject Projectile;
float firingRate = 2f; //delay between shots, in seconds
float lastFired = -100f; //absolute time of last fired shot
// Use this for initialization
void Start()
{
//currentSpeed = Random.Range(MinSpeed, MaxSpeed);
currentSpeed = 4;
x = Random.Range(2f, 2f);
y = 7.0f;
z = 0.0f;
transform.position = new Vector3 (x, y, z);
}
// Update is called once per frame
void Update()
{
float amtToMove = currentSpeed * Time.deltaTime;
transform.Translate(Vector3.down * amtToMove);
if (Time.time < lastFired + firingRate)
{
return;
}
if (transform.position.y <= -6.0)
{
currentSpeed = 4;
// currentSpeed = Random.Range(MinSpeed, MaxSpeed);
transform.position = new Vector3(x, y, z);
}
lastFired = Time.time;
//if (transform.position.y <= 4f)
if (transform.position.y <= 2f)
//currentSpeed = Random.Range(0, 0);
{
Vector3 rightposition = new Vector3(transform.position.x + transform.localScale.x * -8, transform.position.y + transform.localScale.y * 5);
Instantiate(Projectile, rightposition, Quaternion.Euler(0, 0, 90));
}
}
}
Thanks guys, I'm a little unsure how to stick a reward on my post, I cant see the option anywhere.