Hello fellow Unity users, hope everyone is doing great. Wondering if anyone has run into this issue before? I have the script below attached to a cube above the player character. The enemy prefabs spawn perfectly, at random locations around the player when the original prefab has it’s animation component disabled but as soon as I enable animation, the enemy prefabs all spawn in the same location. Does the animation component interfere with the Random.Range calculations? Looks like it does.
Thanks for the help.
//////////////////////////////////////////////////////////////
//
// EnemyGenerator.js
//
//////////////////////////////////////////////////////////////
//
// Script that randomly generates enemies around player
//
//////////////////////////////////////////////////////////////
var linkToEnemyPrefab : Transform;
var CollisionTest : Transform;
private var enemyCount : int = 0;
function Start()
{
var linkToEnemyPrefab = GameObject.Find("Enemy/Enemy");
var CollisionCube = GameObject.Find("First Person Tilt Controls/Player/CollisionTest");
}
function SpawnEnemies()
{
var SpawnBoxX = CollisionTest.transform.position.x + (Random.Range(-20, 20));
var SpawnBoxZ = CollisionTest.transform.position.z + (Random.Range(-20, 20));
var enemyYPosition = 1;
newEnemy = Instantiate(linkToEnemyPrefab, Vector3(SpawnBoxX, enemyYPosition, SpawnBoxZ), Quaternion.Euler(0, (Random.Range(360, -360)), 0));
enemyCount++;
}
function Update()
{
if (enemyCount < 11)
SpawnEnemies();
}