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

Randomly generating Character Controllers?

$
0
0
So I made a prefab of an enemy in my game. It's a character controller instead of a normal gameobject, so that the movement of the enemy was more advanced. I was wondering if it's possible to randomly generate this object? Here's my code (which would work if it was actually a gameObject) using UnityEngine; using System.Collections; public class RandomGenerationEnemy : MonoBehaviour { // Use this for initialization public GameObject[] enemyArray; public int amount; private Vector3 spawnPoint; void Start () { } // Update is called once per frame void Update () { enemyArray = GameObject.FindGameObjectsWithTag("Enemy"); amount = enemyArray.Length; if (amount != 2) { spawnEnemy(); } } void spawnEnemy() { spawnPoint.x = Random.Range(700, 800); spawnPoint.y = 21.6f; spawnPoint.z = Random.Range(500, 600); Instantiate(enemyArray[UnityEngine.Random.Range(0, enemyArray.Length - 1)], spawnPoint, Quaternion.identity); CancelInvoke(); } } now I've already tried this, but the problem is that it won't work because Enemy isn't tagged. I assume it's because my enemy is a character controller. If this is the case can anyone tell me how I can modify this so it works with character controllers? And if it really is the game object why isn't it working?

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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