- Home /
Needing help on Delaying and Freezing Axis.
So I am trying to Delay A command and Freeze All The Axis for my die function on my charachter.
delaying here //Wait .1 seconds to call the next line
Freezing Axis here //Freeze all points/axis
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerCombat : MonoBehaviour { public Rigidbody2D rb; public GameObject Player; public Animator animator; [Space] public LayerMask enemyLayers; [Space] public Transform attackPoint; public float attackRange = 0.5f; public int attackDamage = 15; [Space] public float attackRate = 2f; float nextAttackTime = 0f; [Space] public int maxHealth = 100; int currentHealth;
// Start is called before the first frame update
void Start()
{
currentHealth = maxHealth;
}
public void TakeDamage(int damage)
{
currentHealth -= damage;
animator.SetTrigger("Hurt");
if (currentHealth <= 0)
{
animator.SetBool("IsDead", true);
//Wait .1 seconds to call the next line
Invoke("Die()", 0.1f);
}
void Die()
{
animator.SetBool("IsDead", true);
rb.constraints = RigidbodyConstraints2D.FreezeAll;
//Freeze all points/axis
GetComponent<Animator>().enabled = false;
GetComponent<Collider2D>().enabled = false;
this.enabled = false;
}
// Update is called once per frame
void Update()
{
if (Time.time >= nextAttackTime)
{
if (Input.GetButtonDown("Fire1"))
{
Attack();
nextAttackTime = Time.time + 1.5f / attackRate;
}
}
}
void Attack()
{
animator.SetTrigger("Attack");
Collider2D[] hitEnemeies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
foreach (Collider2D enemy in hitEnemeies)
{
enemy.GetComponent<Enemy>().TakeDamage(attackDamage);
}
}
void OnDrawGizmosSelected()
{
if (attackPoint == null)
return;
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
}
}
}
I am not sure what to do that will work without errors, I am not even sure if "delaying" is what I need?
okay I got the constraints to freeze, but I still need know how to delay
If I can get an answer that would be great, really any information is good