From 18e2f5b45ab0be301f0973b8cf6df714c2d05f7c Mon Sep 17 00:00:00 2001 From: miepzerino <o.skotnik@gmail.com> Date: Fri, 04 Apr 2025 18:43:10 +0000 Subject: [PATCH] #37 set background to character position on load --- Assets/Scripts/UI/Tiling.cs | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/Assets/Scripts/UI/Tiling.cs b/Assets/Scripts/UI/Tiling.cs index 1f40aa7..db8e15b 100644 --- a/Assets/Scripts/UI/Tiling.cs +++ b/Assets/Scripts/UI/Tiling.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using static AnimationStrings; [RequireComponent(typeof(SpriteRenderer))] public class Tiling : MonoBehaviour @@ -127,6 +128,18 @@ myTransform.position.z ); + // Adjust the new position so it fits with the BoxCollider2D size + // Adjust the new position based on whether y is positive or negative + float colliderHeight = GetComponent<BoxCollider2D>().size.y; + if (newPosition.y >= 0) + { + newPosition.y -= Mathf.Abs(newPosition.y) % colliderHeight; + } + else + { + newPosition.y += Mathf.Abs(newPosition.y) % colliderHeight; + } + Transform newBuddy = Instantiate(myTransform, newPosition, myTransform.rotation); Tiling buddyTiling = newBuddy.GetComponent<Tiling>(); -- Gitblit v1.9.3