- Home /
How to get a panel to teleport to a set if coordinates once it reaches a set of coordinates c#
Hello! I've been researching for a day or two and could not find any help on this subject. I am making a game in C# that will have the same rain effect as the background falling cookies in Cookie clicker. I have got everything I want, even the part where the background moves downward on the y-axis, but here is the problem. I can't get it to repeat back to the top of the screen so it gives the impression of it being infinite. I've tried stuff like MoveObject(transform), transform.position, and so on. But what I've realized is that I can only get it to show RectTransform's Left, Right, Top, Bottom, and Pos Z. I'm trying to move a panel with a bunch of images in it instead of a single button.
Here is the script I've made so far:
using UnityEngine; using System.Collections;
public class MoveFlyingEmails : MonoBehaviour { //KEEP //top: 1191.208 <-- once a section of flying emails gets here //bottom: -1191.208 <-- Once a section of flying emails gets here public int toptop = 1191; public int topbottom = -1191; public int bottomtop = -926; public int bottombottom = 926; public int yPosBottom; public int xPosBottom; public int yPosTop; public int xPosTop; void Update() { if (transform.position.x == xPosBottom) { if (transform.position.y == yPosBottom) teleporttoTop(); } } public void teleporttoTop() { transform.position = new Vector3(0, 0, 0); } }
Thank you in advance.
Answer by Hydroid · Dec 10, 2016 at 05:49 PM
Okay, I fixed it. here is the code I used that worked:
using UnityEngine;
using System.Collections;
public class MoveFlyingEmails : MonoBehaviour
{
void Update()
{
if (transform.position.y <= -2507.5f)
{
teleporttoTop();
}
}
public void teleporttoTop()
{
transform.position = new Vector3(503.5f, 1200, 0);
Vector3 newPos = new Vector3(503.5f, 1200, 0);
transform.parent.position = newPos;
Debug.Log("Successfully teleported!");
}
}