object spawn

Hello,
how is it to be provided possibly objects only between A and B,

even if the screen resolution from, for example, 800x600 on1280x720 changes?

M.f.G

Alex.W

translate from de.pons.com/text-übersetzung

You can use the Camera to find the left & right edge of the screen at any resolution.

float zPosition = transform.position.z;
Vector3 topLeft = Camera.main.ViewportToWorldPoint(Vector2.up); // (0,1,0)
Vector3 topRight = Camera.main.ViewportToWorldPoint(Vector2.one); // (1,1,0)

// set z
topLeft.z = zPosition;
topRight.z = zPosition;

// random position
Vector3 spawnPoint = Vector3.Lerp(topLeft, topRight, UnityEngine.Random.value);
1 Like