nikola with 7 hours of love
This commit is contained in:
cemt1363
2026-06-07 07:20:09 +02:00
parent 9e47568284
commit e250dd7d98
8 changed files with 2083 additions and 82 deletions
+3
View File
@@ -76,6 +76,9 @@ public class DamageHandler : MonoBehaviour
private void OnCollisionEnter2D(Collision2D other)
{
if(other.collider.CompareTag("Finish")){
SceneManager.LoadScene(5, LoadSceneMode.Single);
}
float fallSpeed = lastYVelocity;
// Check if we hit hard enough
+23
View File
@@ -1,11 +1,22 @@
using Unity.Cinemachine;
using UnityEngine;
public class PatternSelecter : MonoBehaviour
{
[SerializeField]
private int lastTreeNumber = 8;
public SpriteRenderer spriteRenderer;
public Sprite endTreeSprite;
public BoxCollider2D confine;
public CinemachineConfiner2D confiner2D;
void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
confine = GameObject.Find("CameraConfine").GetComponent<BoxCollider2D>();
confiner2D = GameObject.Find("CinemachineCamera").GetComponent<CinemachineConfiner2D>();
foreach (Transform child in transform)
{
child.gameObject.SetActive(false);
@@ -15,10 +26,22 @@ public class PatternSelecter : MonoBehaviour
{
transform.GetChild(0).gameObject.SetActive(true);
}
else if (TreeSpawner.treeCount == lastTreeNumber) // end tree case
{
transform.GetChild(transform.childCount - 1).gameObject.SetActive(true);
spriteRenderer.sprite = endTreeSprite;
transform.localScale = new Vector3(1.05f, 1.05f, 1.05f);
transform.localPosition += new Vector3(0.27f,0.54f,0f);
confine.size += new Vector2(0f, 38f);
confiner2D.InvalidateBoundingShapeCache();
}
else
{
int randomIndex = Random.Range(1, transform.childCount - 1);
transform.GetChild(randomIndex).gameObject.SetActive(true);
confine.size += new Vector2(0f,43f);
confiner2D.InvalidateBoundingShapeCache();
}
}
}
+27 -40
View File
@@ -1,59 +1,46 @@
using System;
using UnityEngine;
public class TreeSpawner : MonoBehaviour
{
[SerializeField]
private GameObject treePrefab;
[SerializeField]
private GameObject treeEndPrefab;
public GameObject treePrefab;
public Transform player;
[SerializeField]
private static int maxTreeCount = 1;
private bool hasSpawned = false;
public static int treeCount;
private SpriteRenderer spriteRenderer;
private void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
}
void Update()
{
if (hasSpawned == false && treeCount < maxTreeCount)
{
if (player.position.y < transform.position.y - 3f)
{
hasSpawned = true;
if (hasSpawned) return;
float treeHeight = spriteRenderer.bounds.size.y;
Vector3 spawnPos = transform.position + Vector3.down * treeHeight + new Vector3(0, 0.2f, 0);
treeCount++;
Debug.Log($"Spawned Treee{treeCount}");
if(treeCount == maxTreeCount)
{
spawnPos += new Vector3(0.27f,0.54f,0);
Instantiate(treeEndPrefab, spawnPos, Quaternion.identity);
}
else Instantiate(treePrefab, spawnPos, Quaternion.identity);
}
}
Debug.Log("Player Y: " + player.position.y + " | Tree Y + 2: " + (transform.position.y + 2f));
// Delete trees that are far above the player
if (player.position.y < transform.position.y - 40f)
if (player.position.y < transform.position.y - 2f)
{
gameObject.SetActive(false);
}
else
{
gameObject.SetActive(true);
Debug.Log("AUTO SPAWN TRIGGERED");
hasSpawned = true;
float treeHeight = GetComponent<SpriteRenderer>().bounds.size.y;
Vector3 spawnPos =
transform.position +
Vector3.down * treeHeight +
new Vector3(0, 0.2f, 0);
treeCount++;
GameObject newTree = Instantiate(treePrefab, spawnPos, Quaternion.identity);
TreeSpawner spawner = newTree.GetComponent<TreeSpawner>();
spawner.player = player;
spawner.treePrefab = treePrefab;
}
}
}
}