Last active
January 30, 2025 01:20
-
-
Save TheCuttlefish/8d8b14c161cca152f449c3a16c79dd67 to your computer and use it in GitHub Desktop.
Swap tiles ahead of the player in parallax style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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