• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by elilittrell · Dec 04, 2020 at 02:53 AM · delayfreezepositionfreezerotation

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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image elilittrell · Dec 08, 2020 at 03:50 AM 0
Share

okay I got the constraints to freeze, but I still need know how to delay

avatar image elilittrell · Dec 08, 2020 at 03:51 AM 0
Share

If I can get an answer that would be great, really any information is good

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

138 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiated objects ignore most of the collisions. -1 Answers

Turn on Specific Axis Constraints - Keeping Others Selected (JS) 1 Answer

Rigidbody: Freeze All vs InKinematic 0 Answers

cannot have all constraints on in rigidbody? 1 Answer

How do you REALLY freeze a Rigid Body (no dragging allowed)? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges