Beispiel #1
0
    IEnumerator FuseExplode()
    {
        yield return(new WaitForSeconds(fuse));

        Collider[] colliders = Physics.OverlapSphere(transform.position, radius);
        foreach (Collider c in colliders)
        {
            Rigidbody rb = c.GetComponentInParent <Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(power, transform.position, radius, lift);
            }

            HealthBase health = c.GetComponentInParent <HealthBase>();
            if (health != null)
            {
                health.TakeDamage(damage);
            }
        }

        GameObject explosion = Instantiate(explosionPrefab, transform.position, Quaternion.LookRotation(Vector3.up));

        Destroy(explosion, 10);

        Destroy(gameObject);
    }
Beispiel #2
0
    public override void Fire()
    {
        if (playerCamera == null)
        {
            playerCamera = GetComponentInParent <Camera>();
        }

        if (!scope.Scoped())
        {
            animator.SetTrigger("Hip Fire");
        }

        // Check for impact. If present, continue.
        RaycastHit hit;

        if (!Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, Mathf.Infinity))
        {
            return;
        }

        HealthBase enemy = hit.collider.GetComponentInParent <HealthBase>();

        if (enemy != null)
        {
            enemy.TakeDamage(damage);
        }

        IBleedable target = hit.collider.GetComponentInParent <IBleedable>();

        if (target != null)
        {
            target.Bleed(hit.point, hit.normal);
        }
    }
    private void DoShot(StateController controller, Vector3 direction, Vector3 hitPoint,
                        Vector3 hitNormal = default, bool organic = false, Transform target = null)
    {
        GameObject muzzleFlash = EffectManager.Instance.EffectOneShot((int)EffectList.flash, Vector3.zero);

        muzzleFlash.transform.localPosition    = Vector3.zero;
        muzzleFlash.transform.localEulerAngles = Vector3.left * 90.0f;
        DestroyDelayed destroyDelayed = muzzleFlash.AddComponent <DestroyDelayed>();

        destroyDelayed.DelayTime = 0.5f; // 자동 파괴

        GameObject shotTracer = EffectManager.Instance.EffectOneShot((int)EffectList.tracer, Vector3.zero);
        Vector3    origin     = controller.enemyAnimation.gunMuzzle.position;

        shotTracer.transform.rotation = Quaternion.LookRotation(direction);

        if (target && !organic)
        {
            GameObject bulletHole = EffectManager.Instance.EffectOneShot((int)EffectList.bulletHole, hitPoint + 0.1f * hitNormal);
            bulletHole.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitNormal);
            GameObject instantSpark = EffectManager.Instance.EffectOneShot((int)EffectList.sparks, hitPoint);
        }
        else if (target && organic)                                       // 플레이어
        {
            HealthBase targetHealth = target.GetComponent <HealthBase>(); // 플레이어 생명력
            if (targetHealth)
            {
                targetHealth.TakeDamage(hitPoint, direction, controller.classStats.BulletDamage,
                                        target.GetComponent <Collider>(), controller.gameObject);
            }
        }

        SoundManager.Instance.PlayShotSound(controller.classID, controller.enemyAnimation.gunMuzzle.position, 2.0f);
    }
Beispiel #4
0
    /// <summary>
    /// 실제 사격을 위한 함수
    /// </summary>
    /// <param name="stateController">Enemy</param>
    /// <param name="direction">사격 방향</param>
    /// <param name="hitPoint">총알이 맞는 위치(타겟의 위치와는 다름)</param>
    /// <param name="hitNormal"></param>
    /// <param name="organic">Bullet Hole을 표시할지 말지를 결정</param>
    /// <param name="target">타겟</param>
    private void DoShot(StateController controller, Vector3 direction, Vector3 hitPoint,
                        Vector3 hitNormal = default, bool organic = false, Transform target = null)
    {
        // 총알 발사 이펙트 생성 및 세팅
        GameObject muzzleFlash = EffectManager.Instance.EffectOneShot((int)EffectList.flash, Vector3.zero);

        muzzleFlash.transform.SetParent(controller.enemyAnimation.gunMuzzle);
        muzzleFlash.transform.localPosition    = Vector3.zero;
        muzzleFlash.transform.localEulerAngles = Vector3.left * 90f;
        DestroyDelayed destroyDelayed = muzzleFlash.AddComponent <DestroyDelayed>();

        destroyDelayed.DelayTime = 0.5f; // 0.5초 뒤에 자동으로 삭제

        // 총아 궤적 이펙트 생성 및 세팅
        GameObject shotTracer = EffectManager.Instance.EffectOneShot((int)EffectList.tracer, Vector3.zero);

        shotTracer.transform.SetParent(controller.enemyAnimation.gunMuzzle);
        Vector3 origin = controller.enemyAnimation.gunMuzzle.position;

        shotTracer.transform.position = origin;
        shotTracer.transform.rotation = Quaternion.LookRotation(direction);

        // 피탄 구멍 생성 여부 체크
        if (target && !organic)
        {
            GameObject bulletHole = EffectManager.Instance.EffectOneShot((int)EffectList.bulletHole,
                                                                         hitPoint + 0.01f * hitNormal);
            bulletHole.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitNormal);

            GameObject instantSpark = EffectManager.Instance.EffectOneShot((int)EffectList.shotEffect, hitPoint);
        }
        else if (target && organic)                                       // == player
        {
            HealthBase targetHealth = target.GetComponent <HealthBase>(); // playerHealth
            if (targetHealth)
            {
                targetHealth.TakeDamage(hitPoint, direction, controller.classStats.BulletDamage,
                                        target.GetComponent <Collider>(), controller.gameObject); // maybe floating text
            }
        }

        // (현재 Enemy가 가진 무기 종류에 따라 사운드 재생)
        SoundManager.Instance.PlayShotSound(controller.classID,
                                            controller.enemyAnimation.gunMuzzle.position, 2f);
    }
Beispiel #5
0
    public override void Fire()
    {
        if (playerCamera == null)
        {
            playerCamera = GetComponentInParent <Camera>();
        }

        // Check for impact. If present, continue. Inaccurate when not scoped in
        RaycastHit hit;

        if (scope.Scoped())
        {
            if (!Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, Mathf.Infinity))
            {
                return;
            }
        }
        else
        {
            animator.SetTrigger("Hip Fire");
            Vector3 randomPos = new Vector3(Random.Range(0, playerCamera.pixelWidth), Random.Range(0, playerCamera.pixelHeight), 0);
            Ray     ray       = playerCamera.ScreenPointToRay(randomPos);
            if (!Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                return;
            }
        }

        HealthBase enemy = hit.collider.GetComponentInParent <HealthBase>();

        if (enemy != null)
        {
            enemy.TakeDamage(damage);
        }

        IBleedable target = hit.collider.GetComponentInParent <IBleedable>();

        if (target != null)
        {
            target.Bleed(hit.point, hit.normal);
        }
    }
Beispiel #6
0
    //animation event
    public void BladeAttackEvent()
    {
        Ray        ray = new Ray(mc.transform.position, mc.transform.forward);
        RaycastHit hit;

        //Debug.DrawRay(ray.origin, ray.direction * skillDataInstance.range, Color.red, 1f);
        if (Physics.Raycast(ray, out hit, skillDataInstance.range, skillDataInstance.targetLayer))
        {
            PlayRandomSkillAudio(skillDataInstance.hitClips);
            HealthBase hpObj = hit.transform.GetComponent <HealthBase>();
            Character  cc    = hit.transform.GetComponent <Character>();
            if (hpObj)
            {
                hpObj.TakeDamage(skillDataInstance.damage);                     //could be another chatacter or block
                ShowHitEffect(hit.transform.position, Quaternion.LookRotation(mc.transform.forward));
            }

            if (cc)
            {
                cc.Cmm.AddForce(skillDataInstance.knockForce, mc.transform.forward);
            }
        }
    }