Files
2026-05-27 21:32:22 +02:00

161 lines
4.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<<<<<<< HEAD
using System.Collections;
using UnityEngine;
[RequireComponent(typeof(CapsuleCollider))]
=======
using UnityEngine;
using System.Collections;
>>>>>>> origin/main
public class Hole : MonoBehaviour
{
[Header("Nastavení")]
[Tooltip("Poloměr zachycení do kolika jednotek od středu se item 'vtáhne'")]
public float catchRadius = 0.6f;
[Tooltip("Síla vtahování itemu k díře")]
public float pullForce = 4f;
<<<<<<< HEAD
[Header("Vizuál")]
public Renderer glowRenderer;
=======
[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;
>>>>>>> origin/main
private Vector3 startPosition;
private bool isGlowing = false;
void Awake()
{
startPosition = transform.position;
CircleCollider2D col = GetComponent<CircleCollider2D>();
if (col != null)
{
col.isTrigger = true;
col.radius = catchRadius;
}
}
void Update()
{
<<<<<<< HEAD
}
void OnTriggerStay(Collider other)
{
Debug.Log($"Trigger stay with: {other.gameObject.name}");
DraggableObject draggable = other.GetComponent<DraggableObject>();
if (draggable == null) return;
Debug.Log($"Draggable object detected: {other.gameObject.name}");
float dist = Vector3.Distance(transform.position, other.transform.position);
Rigidbody rb = other.GetComponent<Rigidbody>();
if (rb != null)
{
Debug.Log($"Rigidbody detected: {other.gameObject.name}, distance: {dist}");
Vector3 dir = (transform.position - rb.position).normalized;
rb.AddForce(dir * pullForce * Time.fixedDeltaTime, ForceMode.Impulse);
=======
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)
{
DraggableObject draggable = other.GetComponent<DraggableObject>();
if (draggable == null) return;
float dist = Vector2.Distance(transform.position, other.transform.position);
Rigidbody2D rb = other.GetComponent<Rigidbody2D>();
if (rb != null)
{
Vector2 dir = ((Vector2)transform.position - rb.position).normalized;
rb.AddForce(dir * pullForce * Time.fixedDeltaTime, ForceMode2D.Impulse);
>>>>>>> origin/main
}
if (dist < catchRadius * 0.4f)
{
draggable.OnScored();
SetGlow(false);
}
}
<<<<<<< HEAD
void OnTriggerEnter(Collider other)
{
Debug.Log($"Collider entered: {other.gameObject.name}");
if (other.GetComponent<DraggableObject>() != null) SetGlow(true);
}
void OnTriggerExit(Collider other)
{
Debug.Log($"Collider exited: {other.gameObject.name}");
=======
void OnTriggerEnter2D(Collider2D other)
{
if (other.GetComponent<DraggableObject>() != null) SetGlow(true);
}
void OnTriggerExit2D(Collider2D other)
{
>>>>>>> origin/main
if (other.GetComponent<DraggableObject>() != null) SetGlow(false);
}
void SetGlow(bool active)
{
<<<<<<< HEAD
Debug.Log($"SetGlow: {active}");
=======
>>>>>>> origin/main
isGlowing = active;
if (glowRenderer == null) return;
glowRenderer.enabled = active;
if (active) StartCoroutine(PulseGlow());
}
IEnumerator PulseGlow()
{
while (isGlowing && glowRenderer != null)
{
float t = Mathf.PingPong(Time.time * 3f, 1f);
<<<<<<< HEAD
Color c = glowRenderer.sharedMaterial.color;
glowRenderer.sharedMaterial.color = new Color(c.r, c.g, c.b, Mathf.Lerp(0.3f, 0.9f, t));
=======
Color c = glowRenderer.color;
glowRenderer.color = new Color(c.r, c.g, c.b, Mathf.Lerp(0.3f, 0.9f, t));
>>>>>>> origin/main
yield return null;
}
}
void OnDrawGizmosSelected()
{
Gizmos.color = Color.green;
Gizmos.DrawWireSphere(transform.position, catchRadius);
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position, catchRadius * 0.4f);
}
}