Exemple #1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        SpawnPoint spawnPoint = other.gameObject.GetComponent <SpawnPoint>();

        if (spawnPoint != null)
        {
            if (spawnPoint.transform.position != _spawnPoint.transform.position)
            {
                _spawnPoint.SetActive(false);
                spawnPoint.SetActive(true);
                SetSpawn(spawnPoint);
                _audioSource.PlayOneShot(_checkpoint);
            }
        }

        Enemy enemy = other.gameObject.GetComponent <Enemy>();

        if (!(_currentState is RewindingPlayerState) && enemy != null)
        {
            if (!_takenDamageWithinCooldown)
            {
                _damagedCooldownCounter    = DAMAGE_COOLDOWN;
                _takenDamageWithinCooldown = true;

                _animator.SetBool("tookDamage", true);
                _health--;
                _audioSource.PlayOneShot(_hit);
                UpdateHealthUI();
            }

            if (_health <= 0)
            {
                Respawn();
            }
        }

        Goal goal = other.gameObject.GetComponent <Goal>();

        if (goal != null && !_wonCurrentLevel)
        {
            _wonCurrentLevel = true;
            _audioSource.PlayOneShot(_levelComplete);

            if (SceneChanger.CurrentLevel >= _totalLevels)
            {
                SceneChanger.CurrentLevel = 1;
                SceneChanger.LoadMenu("End");
            }
            else
            {
                SceneChanger.CurrentLevel++;
                SceneChanger.Instance.LoadLevel(SceneChanger.CurrentLevel);
            }
        }

        MovingPlatform movingPlatform = other.gameObject.GetComponent <MovingPlatform>();

        if (movingPlatform != null)
        {
            _onMovingPlatform = true;
            _currentPlatform  = movingPlatform;
        }
        else
        {
            _onMovingPlatform = false;
        }

        _currentState.HandleCollision(other);
    }