everything is working fine other than finding random value… if i change the Location[2], my key object is coming in Location[2] perfectly… But it showing Random.Range error… im not getting the random value i…
Aah, i think i get it now, Right now you’re chosing between 7 numbers, not the 6 numbers you want, when you’re using the random.range “0” counts as a number as well, try using random.range(0,5) instead
Edit; as the above answer seems to be wrong, i’ll try again
could you try rewriting the code so it looks like this?:
var Location : Transform [];
var Key : Transform;
function Update () {
if(Input.GetKeyUp (KeyCode.P))
{
Instantiate(Key, Location[Random.Range(0,6)].position, Quaternion.identity);
}
}
This code seems ok: if you fill the Location array with 6 different empty objects and Key with the prefab, each time you release key P a new Key object should be created in one of the Location positions. Besides initialization errors (Location or Key not assigned), the only thing I think could go wrong with this code is the the Location objects having too low Y coordinates, what would make the objects be created under the terrain.
Kacer… i tried your code but still getting the Method not Found error in the console… i became so sick for finding the solution for this simple task… I think its the Unity problem, i think i might not installed the unity properly…