- Home /
Randomly generating Character Controllers?
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?
Your answer
![](https://koobas.hobune.stream/wayback/20220611234754im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Generate random path in grid 1 Answer
NavMesh giving jerky like motion 0 Answers
Cards To Hand 0 Answers
Collision Detection is too slow 0 Answers