Skip to content

Instantly share code, notes, and snippets.

@TheCuttlefish
Last active January 30, 2025 01:20
Show Gist options
  • Save TheCuttlefish/8d8b14c161cca152f449c3a16c79dd67 to your computer and use it in GitHub Desktop.
Save TheCuttlefish/8d8b14c161cca152f449c3a16c79dd67 to your computer and use it in GitHub Desktop.
Swap tiles ahead of the player in parallax style
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VirtualPlane : MonoBehaviour
{
GameObject player;
int planeSize = 200;
int planeHalf = 100;
// Start is called before the first frame update
void Start()
{
player = GameObject.Find("player");
}
if (transform.position.x > player.transform.position.x + planeHalf)
transform.position += new Vector3(-planeSize, 0, 0);
if (transform.position.x < player.transform.position.x - planeHalf)
transform.position += new Vector3(planeSize, 0, 0);
if (transform.position.y > player.transform.position.y + planeHalf)
transform.position += new Vector3(0, -planeSize, 0);
if (transform.position.y < player.transform.position.y - planeHalf)
transform.position += new Vector3(0, planeSize, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment