Answer the question
In order to leave comments, you need to log in
How to spawn an object in two random positions?
how to create a platform so that it is created exactly in two positions, and not between them?
[SerializeField] private GameObject _prefab;
[ContextMenu("Spawn")]
public void OnSpawn()
{
Vector3 platformPosition = new Vector3(Random.Range(-10f,10f), transform.position.y);
var _instantiate = Instantiate(_prefab, platformPosition, Quaternion.identity);
}
Answer the question
In order to leave comments, you need to log in
As an option, choose a random element from an array of positions.
var positions = new Vector3[2] { new Vector3(10, 0, 0), new Vector3(-10, 0, 0)};
Vector3 platformPosition = positions[Random.Range(0, positions.Length)];
var _instantiate = Instantiate(_prefab, platformPosition, Quaternion.identity);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question