예제 #1
0
    private void OnTriggerStay(Collider other)
    {
        if (!IsAttacking)
        {
            return;
        }
        if ((layerMask.value & 1 << other.gameObject.layer) > 0)
        {
            if (other.gameObject.transform.root.GetComponent <PlayerHitten>())
            {
                if (other.gameObject.transform.root.GetComponent <PlayerIdentity>().PlayerID == PlayerID)
                {
                    return;
                }
                PlayerHitten     hitten        = other.gameObject.transform.root.GetComponent <PlayerHitten>();
                BulletHitInfo_AF bulletHitInfo = new BulletHitInfo_AF();
                bulletHitInfo.hitTransform = other.transform;
                bulletHitInfo.bulletForce  = (other.ClosestPoint(transform.position) - transform.position).normalized * velocity;
                // bulletHitInfo.hitNormal = raycastHit.normal;
                bulletHitInfo.hitPoint = other.ClosestPoint(transform.position);

                if (!playerHittens.Contains(hitten))
                {
                    hitten.OnDamaged(damage, PlayerID);
                    hitten.OnHit(bulletHitInfo);
                    playerHittens.Add(hitten);
                    Instantiate(HitParticle, bulletHitInfo.hitPoint, Quaternion.identity);
                    audioSource.PlayOneShot(HitSFX, volume);
                }
            }
            else if (other.gameObject.transform.root.GetComponent <CreatureBasic>())
            {
                other.gameObject.transform.root.GetComponent <CreatureBasic>().Death();
                other.GetComponent <Rigidbody>().AddForceAtPosition((other.ClosestPoint(transform.position) - transform.position).normalized * velocity * 2, other.ClosestPoint(transform.position));
                Instantiate(HitParticle, other.ClosestPoint(transform.position), Quaternion.identity);
                audioSource.PlayOneShot(HitSFX, volume);
            }


            if (other.gameObject.tag == "Item")
            {
                if (other.gameObject.GetComponent <ItemBasic>())
                {
                    ItemBasic itemBasic = other.gameObject.GetComponent <ItemBasic>();

                    // 記得取消
                    // itemBasic.OnUse();

                    if (!itemBasic.IsHolded)
                    {
                        BulletHitInfo_AF bulletHitInfo = new BulletHitInfo_AF();
                        bulletHitInfo.hitTransform = other.transform;
                        bulletHitInfo.bulletForce  = (other.ClosestPoint(transform.position) - transform.position).normalized * velocity / 30;
                        bulletHitInfo.hitPoint     = other.ClosestPoint(transform.position);
                        itemBasic.AddForce(bulletHitInfo);
                    }
                }
            }
        }
    }
예제 #2
0
    IEnumerator explosion()
    {
        yield return(new WaitForSecondsRealtime(delay));

        Collider[] colliders = Physics.OverlapSphere(transform.position, radius, layerMask);

        BulletHitInfo_AF bulletHitInfo = new BulletHitInfo_AF();

        foreach (Collider collider in colliders)
        {
            if ((layerMask.value & 1 << collider.gameObject.layer) > 0)
            {
                if (collider.gameObject.transform.root.GetComponent <PlayerHitten>())
                {
                    PlayerHitten hitten = collider.gameObject.transform.root.GetComponent <PlayerHitten>();
                    bulletHitInfo.hitTransform = collider.transform;
                    bulletHitInfo.bulletForce  = (collider.ClosestPoint(transform.position) - transform.position).normalized * velocity;
                    // bulletHitInfo.hitNormal = raycastHit.normal;
                    bulletHitInfo.hitPoint = collider.ClosestPoint(transform.position);

                    if (!playerHittens.Contains(hitten))
                    {
                        hitten.OnDamaged(damage, PlayerID);
                    }

                    hitten.OnHit(bulletHitInfo);

                    playerHittens.Add(hitten);
                }
                else if (collider.gameObject.transform.root.GetComponent <CreatureBasic>())
                {
                    collider.gameObject.transform.root.GetComponent <CreatureBasic>().Death();
                    collider.GetComponent <Rigidbody>().AddForceAtPosition((collider.ClosestPoint(transform.position) - transform.position).normalized * velocity * 2, collider.ClosestPoint(transform.position));
                }
            }

            if (collider.gameObject.tag == "Item")
            {
                Debug.Log(collider.gameObject.name);
                if (collider.gameObject.GetComponent <ItemBasic>())
                {
                    ItemBasic itemBasic = collider.gameObject.GetComponent <ItemBasic>();

                    // 記得取消
                    // itemBasic.OnUse();

                    if (itemBasic.IsHolded)
                    {
                        continue;
                    }
                    bulletHitInfo.hitTransform = collider.transform;
                    bulletHitInfo.bulletForce  = (collider.ClosestPoint(transform.position) - transform.position).normalized * velocity;
                    bulletHitInfo.hitPoint     = collider.ClosestPoint(transform.position);
                    itemBasic.AddForce(bulletHitInfo);
                }
            }
        }
        yield return(null);
    }