Repaired hole minigame

This commit is contained in:
2026-04-26 12:55:21 +02:00
parent 74fa735322
commit abbe4842fe
26 changed files with 4471 additions and 282 deletions

View File

@@ -1,6 +1,7 @@
using UnityEngine;
using System.Collections;
using UnityEngine;
[RequireComponent(typeof(CapsuleCollider))]
public class Hole : MonoBehaviour
{
[Header("Nastavení")]
@@ -10,13 +11,9 @@ public class Hole : MonoBehaviour
[Tooltip("Síla vtahování itemu k díře")]
public float pullForce = 4f;
[Header("Pohyb díry (volitelné)")]
public bool hasMovement = false;
public float moveSpeed = 2f;
public Vector2 moveRange = new Vector2(1.5f, 0f);
[Header("Vizuál")]
public SpriteRenderer glowRenderer;
public Renderer glowRenderer;
private Vector3 startPosition;
private bool isGlowing = false;
@@ -35,27 +32,24 @@ public class Hole : MonoBehaviour
void Update()
{
if (hasMovement)
{
float x = startPosition.x + Mathf.Sin(Time.time * moveSpeed) * moveRange.x;
float y = startPosition.y + Mathf.Cos(Time.time * moveSpeed * 0.7f) * moveRange.y;
transform.position = new Vector3(x, y, transform.position.z);
}
}
void OnTriggerStay2D(Collider2D other)
void OnTriggerStay(Collider other)
{
Debug.Log($"Trigger stay with: {other.gameObject.name}");
DraggableObject draggable = other.GetComponent<DraggableObject>();
if (draggable == null) return;
float dist = Vector2.Distance(transform.position, other.transform.position);
Debug.Log($"Draggable object detected: {other.gameObject.name}");
float dist = Vector3.Distance(transform.position, other.transform.position);
Rigidbody2D rb = other.GetComponent<Rigidbody2D>();
Rigidbody rb = other.GetComponent<Rigidbody>();
if (rb != null)
{
Vector2 dir = ((Vector2)transform.position - rb.position).normalized;
rb.AddForce(dir * pullForce * Time.fixedDeltaTime, ForceMode2D.Impulse);
Debug.Log($"Rigidbody detected: {other.gameObject.name}, distance: {dist}");
Vector3 dir = (transform.position - rb.position).normalized;
rb.AddForce(dir * pullForce * Time.fixedDeltaTime, ForceMode.Impulse);
}
@@ -66,18 +60,21 @@ public class Hole : MonoBehaviour
}
}
void OnTriggerEnter2D(Collider2D other)
void OnTriggerEnter(Collider other)
{
Debug.Log($"Collider entered: {other.gameObject.name}");
if (other.GetComponent<DraggableObject>() != null) SetGlow(true);
}
void OnTriggerExit2D(Collider2D other)
void OnTriggerExit(Collider other)
{
Debug.Log($"Collider exited: {other.gameObject.name}");
if (other.GetComponent<DraggableObject>() != null) SetGlow(false);
}
void SetGlow(bool active)
{
Debug.Log($"SetGlow: {active}");
isGlowing = active;
if (glowRenderer == null) return;
glowRenderer.enabled = active;
@@ -89,8 +86,8 @@ public class Hole : MonoBehaviour
while (isGlowing && glowRenderer != null)
{
float t = Mathf.PingPong(Time.time * 3f, 1f);
Color c = glowRenderer.color;
glowRenderer.color = new Color(c.r, c.g, c.b, Mathf.Lerp(0.3f, 0.9f, t));
Color c = glowRenderer.sharedMaterial.color;
glowRenderer.sharedMaterial.color = new Color(c.r, c.g, c.b, Mathf.Lerp(0.3f, 0.9f, t));
yield return null;
}
}