Answer the question
In order to leave comments, you need to log in
Calculates coordinates incorrectly?
It spawns far beyond the boundaries of these very objects, even the translation into world coordinates did not help
public GameObject prefab;
public Transform leftUP;
public Transform rightUP;
public Transform leftDown;
public Transform rightDown;
private void Start()
{
StartCoroutine(SpawnPoints());
}
private IEnumerator SpawnPoints()
{
while(true)
{
float randomX = Random.Range(leftDown.position.x, rightDown.position.x);
float randomY = Random.Range(leftDown.position.x, leftUP.position.x);
Instantiate(prefab, new Vector3(randomX, randomY, 0), Quaternion.identity);
yield return new WaitForSeconds(1f);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question