Hello, I currently have nothing setup for spawning of an enemy. Nor do I have game states. However, is there a way that i can make a script so that every 10 seconds 2 then 4 then 6 then 8 then 10 enemies are spawned at 8 locations. And i mean like 2 could be at 1 1 could be at another 3 more could be at another like that? Thanks Right now I just have me AdvancedAI on my enemy prefab and they chase and attack.
Yes you can do the time/increment. I don't know the fancy way to do it but you could have an int for the number of enemies to spawn & a timer. When the timer reaches the set amount it spawns the enemies (the span locations could be stored in an array & you pick a random number that then relates to the spawn position in that spot in the array), resets the timer & then increments the # of enemies to spawn next time. The main issue you may have is spawning multiple enemies at the one location as that could lead to them spawning inside each other.
Hey uhm I got ti figured out. I want to test to see if there are enemies left, would this work? Code (csharp): if(GameObject.FindGameObjectsWithTag("Enemy") = 0)
You need a double = when checking if something is equal to something, one = is used when setting a value
This is what I have, I'd like to have the spawning hold off until the enemies alive are dead What do I need to do? Code (csharp): using UnityEngine; using System.Collections; public class EnemySpawner : MonoBehaviour { public GameObject Enemy; public float timer = 0f; public float SpawnAreaGive = 1f; public bool enemiesAlive = false; // Use this for initialization void Start () { } // Update is called once per frame void Update () { timer += Time.deltaTime; if (timer >= 12) { GameObject[] enemySpawns = GameObject.FindGameObjectsWithTag("EnemySpawnPoint"); foreach(GameObject spawnPoint in enemySpawns) { if(enemiesAlive = false){ GameObject enemy; enemy = Instantiate(Enemy, new Vector3(spawnPoint.transform.position.x, spawnPoint.transform.position.y, spawnPoint.transform.position.z), spawnPoint.transform.rotation) as GameObject; enemy.name = "Enemy"; enemiesAlive = true; timer = 0; } } } } }
You could create a list for enemies spawned & put each enemy into it when they are spawned & then remove them when they are killed. You can then check the length of the list or a count of the items.
Alright got that! Now for the last thing! I need to set the target to the main camera but I am getting this error? Code (csharp): Assets/Scripts/AdvancedAI.cs(31,17): error CS0029: Cannot implicitly convert type `UnityEngine.GameObject' to `UnityEngine.Transform' Here's the code: How can I set the target to my camera a way that this error will go away? Code (csharp): using UnityEngine; using System.Collections; public class AdvancedAI : MonoBehaviour { float distance; public float lookAtDistance = 25.0F; public float chaseRange = 2050.0F; public float attackRange =4.5F ; public float moveSpeed = 5.0F; public float damping = 6.0F; public float damage = 30.0F; public float attackRepeatTime = .8F; public Transform target; public CharacterController controller; private float verticalMomentum = 0f; private float gravity = -9.8f; private Vector3 moveDirection = Vector3.zero; private float attackTime; //TODO: add in a function to find controller and to locate and assign the player as the target void Start() { attackTime = Time.time; target = GameObject.FindWithTag("MainCamera"); } void Update() { distance = Vector3.Distance(target.position, transform.position); verticalMomentum += gravity * Time.deltaTime; if(distance < lookAtDistance) { LookAt(); } if (distance < attackRange) { AttackPlayer(); } else if (distance < chaseRange) { ChasePlayer(); } } void LookAt() { Quaternion rotation = Quaternion.LookRotation(target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); } void ChasePlayer() { moveDirection = transform.forward; moveDirection *= moveSpeed; moveDirection.y += verticalMomentum * Time.deltaTime; controller.Move(moveDirection * Time.deltaTime); } void AttackPlayer() { //TODO: Need Attack Animations if (Time.time > attackTime) { target.SendMessage("damagePlayer", damage, SendMessageOptions.DontRequireReceiver); attackTime = Time.time + attackRepeatTime; } } void ApplyDamage() { chaseRange += 15; moveSpeed += 1; lookAtDistance += 20; } }
Yup, i cant turn the transform into the camera. I dont know what to do to set the maincamera as my target...
I can't help with that sorry as I haven't used Transform like that. When I set something onto my player I usually use gameobject instead but I don't know if changing it to that would work or risk breaking something else without knowing why you used Transform.