hello…
I am developing 2D game. In my Game Scene… , I am having two kind of enemy, I want to randomly instantiate enemy from these two types…
At a time i want only one instance of enemy from these two. So when one instance of the enemy destroyed after that another instance will be generated…
But for all this to work… i want some idea … I am not finding the way for randomly generation of object …
Pleaze anyone suggest some idea and solve my problem…
Thanx in advance for your help and support…
Update :
Currently i have created single enemy object in GameController Script:
function Update ()
{
if(gameStarted)
{
if(level == 1)
{
if(!once)
{
totalEnimies = 20;
objectiveScore = 660;
enemyObject1 = Instantiate(enemyPrefab1 , new Vector3(0 , 6.892054 , -6.72) ,Quaternion.Euler(0,-90,90));
once = true;
}
}
}
}
Script Attached to my Enemy Prefab :
function Start () {
gameControllerScript = GameObject.Find("Main Camera").GetComponent("GameController");
scoreControllerScript = GameObject.Find("Main Camera").GetComponent("ScoreController");
SetPositionandSpeed();
}
function Update () {
var rotationspeed : float = currentRotationSpeed * Time.deltaTime;
var amttomove : float = currentSpeed * Time.deltaTime;
transform.Translate(Vector3.down * amttomove , Space.World);
transform.Rotate(new Vector3(0 , -1 , 0) * rotationspeed );
if(transform.position.y <= -6.00f)
{
SetPositionandSpeed();
}
}
function SetPositionandSpeed()
{
currentRotationSpeed = Random.Range(minRotationSpeed , maxRotationSpeed);
currentSpeed = Random.Range(minSpeed , maxSpeed);
x = Random.Range(-4.00f , 4.00f);
z = -6.72f;
y = 8.0f;
transform.position = new Vector3(x , y , z);
if(gameControllerScript.gameStarted)
scoreControllerScript.ManageEnimies();
}