I'm making a game where when "time is frozen", after a certain amount of hits, the amount of hits will be affected after time resumes. The way I simulated frozen time was by making the enemies' rigidbodies kinematic. With my current code, after time resumes, nothing happens.
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "enemy")
{
if (animator.GetCurrentAnimatorStateInfo(0).IsName("Barrage") || (animator.GetCurrentAnimatorStateInfo(0).IsName("Hook Punch")))
{
collision.gameObject.GetComponent().AddForce(transform.up * hitForce, ForceMode.Impulse);
}
if (TimeFroze == true)
{
if (animator.GetCurrentAnimatorStateInfo(0).IsName("Barrage"))
{
hits = hits + 1;
for (int i = 0; i < hitrb.Length; i++)
{
hitrb = collision.gameObject.GetComponents();
}
StartCoroutine(Damage());
}
}
}
}
private IEnumerator Damage()
{
yield return new WaitUntil(() => TimeFroze == false);
foreach (Rigidbody enemyrb in hitrb)
{
enemyrb.AddForce((transform.up * hits) * hitForce, ForceMode.Impulse);
}
StopCoroutine(Damage());
}
↧