예제 #1
0
    private void shoot()
    {
        _should_shoot = false;

        if (!_reload_timestamp.HasPassed())
        {
            return;
        }

        if (!Munitions.TryShoot())
        {
            Reload();
            return;
        }

        if (gameObject.GetComponentInParent <Player>() != null)
        {
            AkSoundEngine.PostEvent("Player_Shoot", gameObject);
        }
        else if (gameObject.GetComponent <EnemyBehaviour>() != null)
        {
            AkSoundEngine.PostEvent("Robot_Shoot", gameObject);
        }

        CreateShotEffect();

        if (!Physics.Raycast(_aim_camera_object.position, _aim_camera_object.forward, out var hit, _range))
        {
            create_projectile(_aim_camera_object.position + _aim_camera_object.forward * _range, _aim_camera_object.forward);

            return;
        }

        create_projectile(hit.point, (hit.point - _aim_camera_object.position).normalized);

        var hit_obj = hit.rigidbody?.GetComponent <Targetable>();

        var hit_dto = new HitInfoDto
        {
            Damage      = _damage,
            HitPosition = hit.point,
            Origin      = transform.position
        };

        hit_obj?.Hit(hit_dto);

        if (hit_obj == null)
        {
            Targetable.CreateHitEffect(hit_dto);
        }
    }