Example #1
0
 // Start is called before the first frame update
 void Awake()
 {
     animator    = GetComponent <Animator>();
     player      = GameObject.FindGameObjectWithTag("Player");
     mAudio      = GetComponent <AudioSource>();
     zController = GetComponent <ZController2D>();
 }
Example #2
0
    void Attack(Collider2D other)
    {
        Debug.Log(name + " hit " + other.name);

        // get direction to knockback
        float directionRaw = transform.position.x - other.transform.position.x;
        int   direction    = 0;

        if (directionRaw < 0)
        {
            direction = 1;
        }
        else
        {
            direction = -1;
        }

        // perform knockback

        ZController2D otherController = other.GetComponent <ZController2D>();
        ZombieAttack  otherAttack     = other.GetComponent <ZombieAttack>();
        Animator      otherAnim       = other.GetComponent <Animator>();

        otherController.isStunned = true;
        Vector2 knockback = new Vector2();

        knockback.x = direction * playerKnockback;
        knockback.y = playerKnockbackY;
        other.attachedRigidbody.velocity = knockback;
        otherAnim.SetTrigger("Injured");


        // perform other calculations on Zombie side

        otherAttack.ReceiveDamage(playerDamage, playerStunDuration);
    }