Esempio n. 1
0
    /// <summary>
    /// Disable the hit boxes for the given action. Allows the action to perform collisions
    /// </summary>
    public void DisableHitBoxes(Action action)
    {
        // Ignore this call if the given action is null
        if (action == null)
        {
            return;
        }

        // Cycle through each hit box belonging to the given action
        for (int i = 0; i < action.hitBoxes.Length; i++)
        {
            HitBox hitBoxInfo = action.hitBoxes[i];

            // Disable the hit boxes
            hitBoxInfo.Disable();
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Attack"))
        {
            Attack();
        }

        // TODO: Refactor this to another method
        // Reference: https://answers.unity.com/questions/362629/how-can-i-check-if-an-animation-is-being-played-or.html
        var stateInfo = animator.GetCurrentAnimatorStateInfo(0);

        if (stateInfo.IsName("PLAYER_ATTACK"))
        {
            if (stateInfo.length > stateInfo.normalizedTime)
            {
                attackHitBox.Disable();
            }
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Creates the hit box for the given action.
    /// </summary>
    private void CreateHitBoxes(Action action)
    {
        // Cycle through each HitBox assigned to the action
        for (int i = 0; i < action.hitBoxes.Length; i++)
        {
            // Cache the HitBox being cycled through
            HitBox hitBoxInfo = action.hitBoxes[i];

            // Create a new GameObject for the hit box
            GameObject gameObject = new GameObject("HitBox");
            gameObject.transform.parent = transform;             // TODO: Cache both Transforms
            gameObject.layer            = Brawler.Layer.HitBox;  // This hit box inflicts damage

            // Attach a collider to the hit box
            BoxCollider2D collider = gameObject.AddComponent <BoxCollider2D>();
            collider.offset    = hitBoxInfo.offset;
            collider.size      = hitBoxInfo.size;
            collider.isTrigger = true;

            // Creates a BoneFollower instance which allows the HitBox to follow a bone's actionment
            BoneFollower boneFollower = gameObject.AddComponent <BoneFollower>();
            boneFollower.SkeletonRenderer   = skeleton;
            boneFollower.boneName           = hitBoxInfo.boneName;
            boneFollower.followBoneRotation = true;
            boneFollower.followZPosition    = true;

            // Creates a hitBoxObject component so that the hit box can keep a reference to the HitBox object that it represents
            HitBoxObject hitBox = gameObject.AddComponent <HitBoxObject>();
            hitBox.HitBoxInfo = hitBoxInfo;

            // Cache the HitBox's GameObject and components inside the data container object
            hitBoxInfo.GameObject = gameObject;
            hitBoxInfo.Character  = character;
            hitBoxInfo.Action     = action;
            hitBoxInfo.Collider   = collider;

            // Disable the hit box until the attack action is performed.
            hitBoxInfo.Disable();
        }
    }