W
W
WasTabon2021-04-14 18:51:45
Unity
WasTabon, 2021-04-14 18:51:45

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

1 answer(s)
K
kvinty, 2021-04-15
@WasTabon

And try every time to output randomX and randomY to the log

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question