예제 #1
0
    /// <summary>
    /// check if we have hit something (animation event)
    /// </summary>
    public void CheckForHit()
    {
        //Vector3 boxPosition = transform.position + (Vector3.up * lastAttack.collHeight) + Vector3.right * ((int)lastAttackDirection * lastAttack.collDistance);
        //Vector3 boxSize = new Vector3(lastAttack.collSize / 2, lastAttack.collSize / 2, hitZRange / 2);
        //Collider[] hitColliders = Physics.OverlapBox(boxPosition, boxSize, Quaternion.identity, hitLayerMask);
        Vector3 boxPosition = swordHandPos.position + swordHandPos.forward * 0.5f;
        float   radius      = lastAttack.collDistance;

        Collider[] hitColliders = Physics.OverlapSphere(boxPosition, radius, hitLayerMask);
        int        i            = 0;

        while (i < hitColliders.Length)
        {
            IDamagable <DamageObject> damageObject = hitColliders[i].GetComponent(typeof(IDamagable <DamageObject>)) as IDamagable <DamageObject>;
            if (damageObject != null)
            {
                damageObject.Hit(lastAttack);
                targetHit = true;
            }
            i++;
        }
        if (hitColliders.Length == 0)
        {
            targetHit = false;
        }
    }
예제 #2
0
 void OnTriggerEnter(Collider coll)
 {
     if (coll.CompareTag("Enemy"))
     {
         IDamagable <DamageObject> damagableObject = coll.GetComponent(typeof(IDamagable <DamageObject>)) as IDamagable <DamageObject>;
         if (damagableObject != null)
         {
             damagableObject.Hit(damage);
             if (destroyOnHit)
             {
                 Destroy(gameObject);
             }
         }
     }
 }
예제 #3
0
    public void CheckForHit()
    {
        Vector3 boxPosition = transform.position + (Vector3.up * lastAttack.collHeight) + Vector3.right * ((int)currentDirection * lastAttack.collDistance);
        Vector3 boxSize     = new Vector3(lastAttack.collSize / 2, lastAttack.collSize / 2, hitZRange / 2);

        Collider[] hitColliders = Physics.OverlapBox(boxPosition, boxSize, Quaternion.identity, hitLayerMask);
        int        i            = 0;

        while (i < hitColliders.Length)
        {
            IDamagable <DamageObject> damageObject = hitColliders[i].GetComponent(typeof(IDamagable <DamageObject>)) as IDamagable <DamageObject>;
            if (damageObject != null && damageObject != (IDamagable <DamageObject>) this)
            {
                damageObject.Hit(lastAttack);
            }
            i++;
        }
    }
예제 #4
0
    //checks if we have hit something (Animation Event)
    public void CheckForHit()
    {
        //draws a hitbox in front of the character to see which objects are overlapping it
        Vector3 boxPosition = transform.position + (Vector3.up * lastAttack.collHeight) + Vector3.right * ((int)currentDirection * lastAttack.collDistance);
        Vector3 boxSize     = new Vector3(lastAttack.CollSize / 2, lastAttack.CollSize / 2, hitZRange / 2);

        Collider[] hitColliders = Physics.OverlapBox(boxPosition, boxSize, Quaternion.identity, HitLayerMask);

        for (int i = 0; i < hitColliders.Length; i++)
        {
            //hit a damagable object
            IDamagable <DamageObject> damagableObject = hitColliders [i].GetComponent(typeof(IDamagable <DamageObject>)) as IDamagable <DamageObject>;
            if (damagableObject != null && damagableObject != (IDamagable <DamageObject>) this)
            {
                damagableObject.Hit(lastAttack);
            }
        }
    }
예제 #5
0
    //jump kick in progress
    IEnumerator JumpKickInProgress()
    {
        animator.SetAnimatorBool("JumpKickActive", true);

        //a list of enemies that we have hit
        List <GameObject> enemieshit = new List <GameObject>();

        //small delay so the animation has time to play
        yield return(new WaitForSeconds(.1f));

        //check for hit
        while (playerState.currentState == UNITSTATE.JUMPKICK)
        {
            //draw a hitbox in front of the character to see which objects it collides with
            Vector3    boxPosition  = transform.position + (Vector3.up * lastAttack.collHeight) + Vector3.right * ((int)currentDirection * lastAttack.collDistance);
            Vector3    boxSize      = new Vector3(lastAttack.CollSize / 2, lastAttack.CollSize / 2, hitZRange / 2);
            Collider[] hitColliders = Physics.OverlapBox(boxPosition, boxSize, Quaternion.identity, HitLayerMask);

            //hit an enemy only once by adding it to the list of enemieshit
            foreach (Collider col in hitColliders)
            {
                if (!enemieshit.Contains(col.gameObject))
                {
                    enemieshit.Add(col.gameObject);

                    //hit a damagable object
                    IDamagable <DamageObject> damagableObject = col.GetComponent(typeof(IDamagable <DamageObject>)) as IDamagable <DamageObject>;
                    if (damagableObject != null)
                    {
                        damagableObject.Hit(lastAttack);

                        //camera Shake
                        CamShake camShake = Camera.main.GetComponent <CamShake> ();
                        if (camShake != null)
                        {
                            camShake.Shake(.1f);
                        }
                    }
                }
            }
            yield return(null);
        }
    }
예제 #6
0
    /// <summary>
    /// 进行跳踢
    /// </summary>
    /// <returns></returns>
    IEnumerator JumpKickInProgress()
    {
        playerAnimator.SetAnimatorBool("JumpKickActive", true);

        //击中的敌人列表
        List <GameObject> enemiesHit = new List <GameObject>();

        //延迟0.1s,让动画有时间播放
        yield return(new WaitForSeconds(0.1f));

        //检查是否击中
        while (playerState.currentState == PLAYERSTATE.JUMPKICK)
        {
            //在角色前面绘制一个击中框,以查看与之碰撞的对象
            Vector3    boxPosition  = transform.position + (Vector3.up * lastAttack.collHeight) + Vector3.right * ((int)currentDirection * lastAttack.collDistance);
            Vector3    boxSize      = new Vector3(lastAttack.CollSize / 2, lastAttack.CollSize / 2, hitZRange / 2);
            Collider[] hitColliders = Physics.OverlapBox(boxPosition, boxSize, Quaternion.identity, HitLayerMask);

            //通过将敌人添加到敌人列表中只击中一次
            foreach (Collider col in hitColliders)
            {
                if (!enemiesHit.Contains(col.gameObject))
                {
                    enemiesHit.Add(col.gameObject);

                    //攻击一个对象
                    IDamagable <DamageObject> damagableObject = col.GetComponent(typeof(IDamagable <DamageObject>)) as IDamagable <DamageObject>;
                    if (damagableObject != null)
                    {
                        damagableObject.Hit(lastAttack);

                        //摄像机抖动
                        CameraShake camShake = Camera.main.GetComponent <CameraShake>();
                        if (camShake != null)
                        {
                            camShake.Shake(0.1f);
                        }
                    }
                }
            }
            yield return(null);
        }
    }
예제 #7
0
    //check if we have hit something (Animation Event)
    public void CheckForHit()
    {
        //draw a hitbox in front of the character to see which objects it collides with
        Vector3 boxPosition = transform.position + (Vector3.up * lastAttack.collHeight) + Vector3.right * ((int)lastAttackDirection * lastAttack.collDistance);
        Vector3 boxSize     = new Vector3(lastAttack.CollSize / 2, lastAttack.CollSize / 2, hitZRange / 2);

        Collider[] hitColliders = Physics.OverlapBox(boxPosition, boxSize, Quaternion.identity, HitLayerMask);

        int i = 0;

        while (i < hitColliders.Length)
        {
            //hit a damagable object
            IDamagable <DamageObject> damagableObject = hitColliders[i].GetComponent(typeof(IDamagable <DamageObject>)) as IDamagable <DamageObject>;
            if (damagableObject != null)
            {
                damagableObject.Hit(lastAttack);

                //we have hit something
                targetHit = true;
            }
            i++;
        }

        //nothing was hit
        if (hitColliders.Length == 0)
        {
            targetHit = false;
        }

        //on weapon hit
        if (lastAttackInput == INPUTACTION.WEAPONATTACK && targetHit)
        {
            currentWeapon.onHitSomething();
        }
    }
예제 #8
0
    /// <summary>
    /// 检查我们是否碰了点东西(动画事件)
    /// </summary>
    public void CheckForHit()
    {
        //在角色前面绘制一个点击框,以查看与之碰撞的对象
        Vector3 boxPosition = transform.position + (Vector3.up * lastAttack.collHeight) + Vector3.right * ((int)lastAttackDirection * lastAttack.collDistance);
        Vector3 boxSize     = new Vector3(lastAttack.CollSize / 2, lastAttack.CollSize / 2, hitZRange / 2);

        Collider[] hitColliders = Physics.OverlapBox(boxPosition, boxSize, Quaternion.identity, HitLayerMask);

        int i = 0;

        while (i < hitColliders.Length)
        {
            //击中一个损坏的物体
            IDamagable <DamageObject> damagableObject = hitColliders[i].GetComponent(typeof(IDamagable <DamageObject>)) as IDamagable <DamageObject>;
            if (damagableObject != null)
            {
                damagableObject.Hit(lastAttack);

                //击中了物体,返回true
                targetHit = true;
            }
            i++;
        }

        //武器击中
        if (lastAttackInput == INPUTACTION.WEAPONATTACK && targetHit)
        {
            currentWeapon.OnHitSomething();
        }

        //什么都没击中
        if (hitColliders.Length == 0)
        {
            targetHit = false;
        }
    }