Hello! I think that there probably is a simple solution to this, but, browsing google and different threads around here, I just get more confused, rather than enlightened.
So this is what my Random instantiate code looks like:
void Start () {
InvokeRepeating("Spawn", SpawnStartDelay, SpawnRate);
}
void Spawn() {
Vector2 position = new Vector2(Random.Range(-10.0F, 10.0F),Random.Range(-10.0F, 10.0F));
Instantiate(enemyPrefab, position, Quaternion.identity);
So, how do I reference a “this.gameobject.transform.position” in this kind of script? I’ve been trying different things without success. They just spawn randomly on axis 0,0, as expected.
SarperS
2
const float range = 10.0f;
private void Spawn() {
var randomPos = Random.insideUnitSphere * range;
randomPos.y = 0;
Instantiate(enemyPrefab, transform.position + randomPos, Quaternion.identity);
}