Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Enemies won't attack after they spawn!

$
0
0
I am trying to make my enemies attack my player after they spawn but they just run towards the player, stop, and don't attack. I am making the spawner use the enemy prefab, but when I actually place the enemy in the scene it works. Although when I kill the first enemy they stop spawning. Is there a way to make it so my enemies always look for my player and attack him? Here is my spawn script: using UnityEngine; using System.Collections; public class Spawn : MonoBehaviour { // Spawn location public Vector3 spawnLocation = Vector3.zero; // Spawn radius (Gives a bit more randomness factor to the spawn location) public float spawnRadius = 1.0f; // Spawn timer (seconds) public float spawnTimer = 5.0f; private float spawnTimeRemaining = 5.0f; public GameObject enemyPrefab; // The zombie to spawn public GameObject zombiePrefab = null; void Awake() { spawnTimeRemaining = spawnTimer; } void FixedUpdate() { spawnTimeRemaining -= Time.deltaTime; if (spawnTimeRemaining <= 0) { Vector2 circlePosition = Random.insideUnitCircle * spawnRadius; GameObject.Instantiate(enemyPrefab, spawnLocation + new Vector3(circlePosition.x, 0.0f, circlePosition.y), Quaternion.identity); spawnTimeRemaining = spawnTimer; } } } Any help would be awesome. Thanks :D

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>