示例#1
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == "gate")
     {
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
     }
     if (other.gameObject.tag == "enemy" && !animator.GetBool("dodge") && !animator.GetBool("Hurt") && !dead)
     {
         bool enemyHurt = false;
         if (other.gameObject.transform.root.gameObject.GetComponent <Animator>())
         {
             enemyHurt = other.gameObject.transform.root.gameObject.GetComponent <Animator>().GetBool("Hurt");
         }
         else
         {
             enemyHurt = false;
         }
         if (!enemyHurt)
         {
             if (!cam.getShaking())
             {
                 StartCoroutine(cam.shakeScreen());
             }
             animator.SetBool("Hurt", true);
             heart.SetTrigger("Hurt");
             health -= 10;
             manager.resetMult();
             if (health > 0)
             {
                 rig.velocity = new Vector2(Mathf.Sign(transform.position.x - other.transform.position.x) * 40, rig.velocity.y);
             }
         }
     }
 }
示例#2
0
    // Update is called once per frame
    void OnTriggerEnter2D(Collider2D other)
    {
        float   dir         = Mathf.Sign(other.transform.root.localScale.x);
        Vector2 impactPoint = other.bounds.ClosestPoint(transform.position);

        SwordBehaviour sword = other.gameObject.GetComponent <SwordBehaviour>();

        if (animator)
        {
            isVunerable = !animator.GetBool("Hurt");
        }

        if (other.gameObject.tag == "sword" && sword.activated && isVunerable)
        {
            if (impactEffect)
            {
                Instantiate(impactEffect, impactPoint, Quaternion.identity);
            }
            if (knockback && rig != null)
            {
                rig.velocity = new Vector2(-dir * 20, rig.velocity.y);
            }


            if (animator)
            {
                animator.SetBool("Hurt", true);
            }

            if (animator && !animator.GetBool("Death"))
            {
                if (manager)
                {
                    manager.addScore(10);
                    manager.addMult();
                }
            }
            if (cam && !cam.getShaking())
            {
                StartCoroutine(cam.shakeScreen());
            }
            if (hurtEvent != null)
            {
                hurtEvent.Invoke();
            }
        }
    }
示例#3
0
    // Update is called once per frame
    void OnTriggerEnter2D(Collider2D other)
    {
        float   dir         = Mathf.Sign(other.transform.root.localScale.x);
        Vector2 impactPoint = other.bounds.ClosestPoint(transform.position);

        SwordBehaviour sword = other.gameObject.GetComponent <SwordBehaviour>();

        if (animator)
        {
            isVunerable = !animator.GetBool("Hurt");
        }

        if (other.gameObject.tag == "sword" && sword.activated && isVunerable)
        {
            int vert = 0;
            if (verticalKnockback)
            {
                vert = 10;
            }
            if (produceOrbs && Random.Range(1, 3) == 1)
            {
                Instantiate(memOrbs, transform.position, transform.rotation);
            }
            if (impactEffect)
            {
                Instantiate(impactEffect, impactPoint, Quaternion.identity);
            }
            if (knockback && rig != null)
            {
                rig.velocity = new Vector2(-dir * 20, rig.velocity.y + vert);
            }
            if (verticalKnockback)
            {
                rig.AddTorque(90 * Mathf.Sign(rig.velocity.x));
            }
            //Vector2 impactDir = new Vector2(transform.position.x, transform.position.y) - impactPoint;
            //if (knockback && rig != null) rig.velocity = impactDir.normalized * 20;


            if (animator)
            {
                animator.SetBool("Hurt", true);
            }

            if (animator && !animator.GetBool("Death"))
            {
                if (manager)
                {
                    //manager.addScore(10);
                    //manager.addMult();
                }
            }
            if (cam && !cam.getShaking())
            {
                StartCoroutine(cam.shakeScreen());
            }
            if (hurtEvent != null)
            {
                hurtEvent.Invoke();
            }
        }
    }