Hey so my goal with this code is to control an enemy’s movement as well as have them instantiate a projectile gameObject that flies ahead of them toward the player EVERY “throwRate” seconds.
Important info: My player is motionless, the shurikans are their own gameObject prefab, the enemy is suppose to get close to the player to a certain range and then stop while continuing to throw shurikans.
public float speed = 3f;
public float throwRate = 10f;
public GameObject weapon;
public float throwSpeed = 5f;
GameObject player;
GameObject shurikan;
private Vector3 target;
float distance;
float timer = 0f;
void Start ()
{
player = GameObject.FindGameObjectWithTag("Player");
target = player.transform.position;
}
void Update ()
{
timer += Time.deltaTime;
float distance = Vector3.Distance(transform.position, target);
if (distance > 5)
{
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
// this is the area of trouble.
if (timer >= throwRate)
{
shurikan = Instantiate(Resources.Load ("Shurikan")) as GameObject;
timer = 0f;
}
}
I’m getting the error about cannot convert float into a bool on line 28. Both timer and throwRate are floats and I’m trying to use a simple if statement. I’ve tried using a constant in place of throwRate but it still doesn’t work. I’m still new to Unity, thank you for any help you can offer.