Hello, my application has a fixed scene with a size of 1920 by 1080.
At the top of the scene, a cloud moves along the X coordinate.
What is the best way to make a cloud transfer?
Destroy it when the X coordinates are reached and re-create it in a new X coordinate?
Or move to the initial X coordinate?
Move it.
I used this code
[SerializeField] private float speed;
private Vector3 tempPos;
public void Start()
{
tempPos = transform.position;
}
private void Update()
{
tempPos.x += Time.deltaTime * speed;
Screen.width
// Move X
if (tempPos.x >= 210.0f)
{
tempPos.x = -300.0f;
}
else
{
print(tempPos.x);
}
this.transform.position = tempPos;
}
I can’t figure out how to calculate the coordinates in which to move the object, because there are no pixels there…
Maybe logically it would be right to find out the width of the client’s screen and start from this value, but I don’t have enough knowledge.
Thank you for your answers!
That’s where I would start.
The Camera
class has various methods that may be useful here, such as this one:
https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
or this one:
https://docs.unity3d.com/ScriptReference/Camera.ViewportToWorldPoint.html
The Screen
class has information about the screen resolution.