Want my enemies to come from different positions everytime i play the game..

I hope you understand my point - Just incase let me elaborate

When my game starts my soldier is standing in the corridor and as i go near the door, enemy comes buttt…

what i want is - whenever i start the game, my enemy positions should be “un” predictable throughout the game.

First i want to achieve this…

Then i want to add a time interval, like if i kill 1 enemy, 2nd enemy should come in front of hero after lets say after 30-40 seconds

Please advise me with 1st part , what sample should i use to start off and how to make enemy positions unpredicable…

Shall i do something like - make an area and when hero enters that area, the enemy in that area comes [but from unpredicable] position

Please give me best advise

Random.Range is your pal.

Any random type instruction. You could do it many ways. Have a random int created, that int say 1-10 each represents a different position.
Or would could just generate random floats, each with a min max value. All would work.

:))( K sweet heart.

Also I think that your random position generator should be inside of one loop. Because the random position can be inside of some wall or something weird.

will work on a dummy thing and post the project here for further mapping, is something like this available here ? like with a cylinder and cube ?

thank you

you could have multiple spawn point.
But eventually the player would guess this location.

then what is the situation ?

This is:

+1

i am little confused here, how my way points work with random range ?? u got me ??

there is code on the script referance?

// Instantiates prefab somewhere between -10.0 and 10.0 on the x-z plane 
var prefab : GameObject;
function Start () 
{    
var position: Vector3 = Vector3(Random.Range(-10.0, 10.0), 0, Random.Range(-10.0, 10.0));  

  Instantiate(prefab, position, Quaternion.identity);
}

Just use that but use a difernt function and once they are dead instantiate a new badguy.

we dont know your code so how can we give you help on your waypoints?

i am working on it right now, most probably will update here if i get into any sought of issue

these are good for you and your randomness needs.
:::)))(((

what I would do is have say a dozen position vectors, stored in an array. Then I would create a random number on call. I would then associate that number with one member of the array so it would look like this…

var unityPositionArray : Vector3[];
var unityPosition : Array;
var enemyObject : GameObject;

function Start () 
{
	unityPosition  = new Array(unityPositionArray);
	InvokeRepeating("thisThing", 0.1, 2.0);
}
function thisThing()
{   
	var min : int = 0;
	var max : int = 10;
    var randomNumber: int = Random.Range(min, max);
    print(randomNumber);
    enemyObject.transform.position = unityPosition[randomNumber];
}

Hope that helps!!
:)))(

OK, lets look at this in sections.

First, we need a way to figure out where the monster should come from. For this, I suggest a 3 part check. 1) a random direction, 2) a random distance and 3) a Linecast to determine if we can be put there.

To solve this, you would need a function that Gets a Random Position based on these factors.

function GetRandomPosition(){
	var dir = Vector3.Scale(Random.insideUnitSphere, Vector3(1,0,1)).normalized;
	var pos = transform.TransformPoint(dir * Random.Range(minRange, maxRange);
	var hit : RaycastHit;
	if(Physics.Linecast(transform.position, pos, hit)){
		pos = hit.point + Vector3.Scale(hit.normal, Vector3(1,0,1)).normalized;
	}
	return pos;
}

Notice that the Vector3.Scales, this keeps everything level.

Next, we need to keep track of our monsters. To do this, I suggest a List object like so:

import System.Collections.Generic;

private var monsters : List.<GameObject>;

This might seem like overkill for simply adding a monster to the scene, but it will make sense later.

Next we need to have a function that will Add a monster to it, as well as set a facing for the monster initially.

var monsterPrefab : GameObject;

function AddMonster(){
	monsters.Add(Instantiate(mosnterPrefab, GetRandomPosition(), Quaternion.identity);
	LookAtPlayermonsters[monsters.Count - 1]);
}

function LookAtPlayer(go : GameObject){
	go.transform.LookAt(transform);
	go.localEulerAngles.x = 0;
}

With this, we can now track monsters. By using List.Count we can see how many monsters we currently have in our scene. So we will need some more tracking. This time, Time. Since you want them to come out 30 to 40 seconds after the first one dies. Also, we need to know when the monster dies. Lastly, we will keep track of the time that the monster should come out.

var minRange : float;
var maxRange : float;
private nextMonster : float = Mathf.infinity;

function Start(){
	AddMonster();
}

function Update(){
	var count = monsters.Count;
	for(var i=0; i<monsters.Count; i++){
		if(monsters[i] == null){
			monsters.RemoveAt(i);
			i--;
		}
	}
	if(monsters.Count > count  nextMonster == Mathf.infinity){
		nextMonster = Time.time + 30 + Random.Range(0, 10);
	}
	
	if(Time.time > nextMonster){
		AddMonster();
		nextMonster = Mathf.infinity;
	}
}

OK, so lets walk through it.

We start by adding a monster. this is done in a random position according to GetRandomPosition. The monster is set to look at the player (note that we also set the x rotation back to zero so he is upright)

Every frame, we check to see if the “Count” changes, if not we wait until next frame.

OK, we kill our monster, and the Update check sees that the model is no longer there. So it says. “Hey, our count is now less than what it was.” We set the nextMonster to the time that our next monster should appear (30 + 0 to 10)

Every frame, we then check to see if our time is up for introducing the next monster, if so, we add it and set nextMonster to infinity so it wont pop out another next frame.

OK, for some changes… Lets add this stuff:

// variables
var newMonsterEvery : float = 20;
private var newMonster : float = newMonsterEvery;

// add this to the Update
	if(Time.time > newMonster){
		AddMonster();
		newMonster += newMonsterEvery;
	}

Thsi code then simply adds a new mosnter every 20 seconds. And with the overkill List we are using, this now keeps track of all the monsters. Any time Any monster is killed it will trigger adding another, but not reset the nextMonster counter.