コード例 #1
0
    public void PressInteraction()
    {
        if (_attackCooldownTimer <= 0 && !_roomInhabitant.IsBeingSuckedIntoSpace && !IsStunned)
        {
            _attackCooldownTimer = _attackCooldown;
            PlayEmote(AstronautEmote.Attack);

            GameObject attackFx = Instantiate(_attackFxPrefab, transform.position, transform.rotation);
            Destroy(attackFx, 3.0f);

            if (_roomInhabitant.CurrentDevice != null)
            {
                _roomInhabitant.CurrentDevice.TriggerInteraction(gameObject);

                // Always drain the battery after all interactions (if not drained already)
                if (_batteryComponent != null && _roomInhabitant.CurrentDevice.DrainsBatteryOnInteraction())
                {
                    _batteryComponent.DrainCharge();
                }
            }

            if (_canStun)
            {
                TryWhackAstronaut();
            }
        }
    }
コード例 #2
0
    private void TryWhackAstronaut()
    {
        for (int i = 0; i < AstronautController.Instances.Count; ++i)
        {
            AstronautController astro = AstronautController.Instances[i];
            if (astro != this)
            {
                Vector3 toAstro = (astro.transform.position - transform.position).WithY(0);
                if (toAstro.magnitude < 2.5f)
                {
                    if (_hitSound)
                    {
                        AudioManager.Instance.PlaySound(gameObject, _hitSound);
                    }

                    astro.GetWhacked(transform.position);

                    BatteryComponent battery = GetComponent <BatteryComponent>();
                    if (battery != null && battery.HasCharge)
                    {
                        astro.RoomInhabitant.NotifySuckedIntoSpace();
                        battery.DrainCharge();
                    }

                    return;
                }
            }
        }
    }
コード例 #3
0
    protected override void OnInteractionPressed(GameObject gameObject)
    {
        BatteryComponent battery = gameObject.GetComponentInChildren <BatteryComponent>();

        if (battery != null && battery.HasCharge)
        {
            battery.DrainCharge();
            OpenNextDoor();
        }
    }