2025-09-01 05:03:00 +05:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Collections;
|
2025-09-04 12:13:13 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using DG.Tweening;
|
2025-09-01 05:03:00 +05:00
|
|
|
|
public class CubeClash_TimeBomb : MonoBehaviour
|
|
|
|
|
{
|
2025-09-04 12:13:13 +05:00
|
|
|
|
[Header("Timing")]
|
2025-09-01 05:03:00 +05:00
|
|
|
|
public float countdown = 3f;
|
2025-09-04 12:13:13 +05:00
|
|
|
|
|
|
|
|
|
[Header("Explosion")]
|
2025-09-01 05:03:00 +05:00
|
|
|
|
public float radius = 3f;
|
2025-09-04 12:13:13 +05:00
|
|
|
|
public float explosionForce = 20f;
|
|
|
|
|
[Tooltip("Upward bias for the explosion force. 0 = flat; 1<>2 = nice pop.")]
|
|
|
|
|
public float upwardModifier = 1.0f;
|
|
|
|
|
public ForceMode forceMode = ForceMode.Impulse;
|
|
|
|
|
|
|
|
|
|
[Header("Death")]
|
|
|
|
|
[Tooltip("How long to let physics play after the blast before destroying Zibus.")]
|
|
|
|
|
public float killDelay = 0.7f;
|
|
|
|
|
|
|
|
|
|
[Header("Filters (optional)")]
|
|
|
|
|
[Tooltip("Only Rigidbodies on these layers will be pushed. Leave as ~0 (Everything) to affect all.")]
|
|
|
|
|
public LayerMask pushMask = ~0;
|
|
|
|
|
[Tooltip("Layers considered 'Zibu bodies' for killing. Leave as ~0 (Everything) if you use tags/components instead.")]
|
|
|
|
|
public LayerMask zibuMask = ~0;
|
|
|
|
|
public GameObject bombMesh;
|
|
|
|
|
public GameObject bombFX;
|
2025-09-01 05:03:00 +05:00
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
StartCoroutine(ExplodeRoutine());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator ExplodeRoutine()
|
|
|
|
|
{
|
2025-09-04 12:13:13 +05:00
|
|
|
|
//transform.DOJump(Vector3.zero + new Vector3(Random.Range(-1.5f, 1.5f),1, Random.Range(-1.5f, 1.5f)),2,1,1);
|
|
|
|
|
transform.DOMove(Vector3.zero + new Vector3(Random.Range(-1.5f, 1.5f), 1, Random.Range(-1.5f, 1.5f)), 1).SetEase(Ease.Linear);
|
|
|
|
|
|
|
|
|
|
yield return new WaitForSeconds(countdown+1);
|
|
|
|
|
bombMesh.SetActive(false);
|
|
|
|
|
bombFX.SetActive(true);
|
|
|
|
|
// 1) Gather colliders in radius
|
|
|
|
|
Collider[] cols = Physics.OverlapSphere(transform.position, radius, pushMask, QueryTriggerInteraction.Ignore);
|
|
|
|
|
|
|
|
|
|
// 2) Unique sets of rigidbodies to push and zibus to kill
|
|
|
|
|
HashSet<Rigidbody> bodies = new HashSet<Rigidbody>();
|
|
|
|
|
HashSet<GameObject> zibusToKill = new HashSet<GameObject>();
|
|
|
|
|
|
|
|
|
|
foreach (var col in cols)
|
2025-09-01 05:03:00 +05:00
|
|
|
|
{
|
2025-09-04 12:13:13 +05:00
|
|
|
|
if (!col) continue;
|
|
|
|
|
|
|
|
|
|
// Collect rigidbodies to push
|
|
|
|
|
if (col.attachedRigidbody != null)
|
|
|
|
|
bodies.Add(col.attachedRigidbody);
|
|
|
|
|
|
|
|
|
|
// Collect Zibus to kill (by tag OR by component on self/parent)
|
2025-09-01 05:03:00 +05:00
|
|
|
|
if (col.CompareTag("Zibu"))
|
|
|
|
|
{
|
2025-09-04 12:13:13 +05:00
|
|
|
|
zibusToKill.Add(col.transform.root.gameObject);
|
2025-09-01 05:03:00 +05:00
|
|
|
|
}
|
2025-09-04 12:13:13 +05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var ctrl = col.GetComponentInParent<CubeClash_ZibuController>();
|
|
|
|
|
if (ctrl) zibusToKill.Add(ctrl.gameObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3) Apply explosion force to all rigidbodies
|
|
|
|
|
foreach (var rb in bodies)
|
|
|
|
|
{
|
|
|
|
|
// If you froze X/Z rotation on your character RBs, clear it so they can tumble from the blast
|
|
|
|
|
if ((rb.constraints & (RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ)) != 0)
|
|
|
|
|
rb.constraints &= ~(RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ);
|
|
|
|
|
|
|
|
|
|
rb.AddExplosionForce(explosionForce, transform.position, radius, upwardModifier, forceMode);
|
2025-09-01 05:03:00 +05:00
|
|
|
|
}
|
2025-09-04 12:13:13 +05:00
|
|
|
|
|
|
|
|
|
// 4) Put Zibus into a brief "ragdoll" / inert state so the shove reads clearly
|
|
|
|
|
foreach (var go in zibusToKill)
|
|
|
|
|
{
|
|
|
|
|
var ctrl = go.GetComponent<CubeClash_ZibuController>();
|
|
|
|
|
if (ctrl)
|
|
|
|
|
{
|
|
|
|
|
// Stop their control for the duration
|
|
|
|
|
ctrl.ApplyPushStun(Mathf.Max(killDelay, 0.25f));
|
|
|
|
|
|
|
|
|
|
// If they have an AI, disable it so it doesn't cancel the shove
|
|
|
|
|
var ai = go.GetComponent<CubeClash_ZibuAI>();
|
|
|
|
|
if (ai) ai.enabled = false;
|
|
|
|
|
|
|
|
|
|
// Optional: close any open parachute
|
|
|
|
|
ctrl.ForceCloseParachute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var rb = go.GetComponent<Rigidbody>();
|
|
|
|
|
if (rb)
|
|
|
|
|
{
|
|
|
|
|
// Ensure physics is active and allowed to spin
|
|
|
|
|
rb.isKinematic = false;
|
|
|
|
|
rb.useGravity = true;
|
|
|
|
|
rb.constraints &= ~(RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 5) Wait, then delete the Zibus
|
|
|
|
|
yield return new WaitForSeconds(killDelay);
|
|
|
|
|
|
|
|
|
|
foreach (var go in zibusToKill)
|
|
|
|
|
{
|
|
|
|
|
if (go) Destroy(go);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 6) Finally destroy the bomb object
|
2025-09-01 05:03:00 +05:00
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
2025-09-04 12:13:13 +05:00
|
|
|
|
|
|
|
|
|
// Optional: visualize radius in Scene view
|
|
|
|
|
void OnDrawGizmosSelected()
|
|
|
|
|
{
|
|
|
|
|
Gizmos.color = new Color(1f, 0.5f, 0f, 0.35f);
|
|
|
|
|
Gizmos.DrawSphere(transform.position, radius);
|
|
|
|
|
Gizmos.color = new Color(1f, 0.5f, 0f, 1f);
|
|
|
|
|
Gizmos.DrawWireSphere(transform.position, radius);
|
|
|
|
|
}
|
2025-09-01 05:03:00 +05:00
|
|
|
|
}
|
2025-09-04 12:13:13 +05:00
|
|
|
|
|
|
|
|
|
//using UnityEngine;
|
|
|
|
|
//using System.Collections;
|
|
|
|
|
|
|
|
|
|
//public class CubeClash_TimeBomb : MonoBehaviour
|
|
|
|
|
//{
|
|
|
|
|
// public float countdown = 3f;
|
|
|
|
|
// public float radius = 3f;
|
|
|
|
|
|
|
|
|
|
// void Start()
|
|
|
|
|
// {
|
|
|
|
|
// StartCoroutine(ExplodeRoutine());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// IEnumerator ExplodeRoutine()
|
|
|
|
|
// {
|
|
|
|
|
// yield return new WaitForSeconds(countdown);
|
|
|
|
|
// Collider[] cols = Physics.OverlapSphere(transform.position, radius);
|
|
|
|
|
// foreach (Collider col in cols)
|
|
|
|
|
// {
|
|
|
|
|
// if (col.CompareTag("Zibu"))
|
|
|
|
|
// {
|
|
|
|
|
// Destroy(col.gameObject);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// Destroy(gameObject);
|
|
|
|
|
// }
|
|
|
|
|
//}
|