Ejemplo n.º 1
0
    void Update()
    {
        doSteering();

        for (int i = 0; i < _holes.Length; i++)
        {
            CurrentHp = _currentHp - _holes[i].GetWaterPerSec() * Time.deltaTime;
        }

        _water.SetWaterLevel(1 - _currentHp / MaxHp);

        float floatingHeight = Mathf.Lerp(_floatingHeightEmpty, _floatingHeightFull, _water.GetWaterLevel());

        _floatingObject.yAdjustment = floatingHeight;

        // If water level reaches max, the ship sink
        if (_water.GetWaterLevel() >= 1.0f && !_floatingObject.isSinking)
        {
            _floatingObject.isSinking  = true;
            _floatingObject.isFloating = false;
            _floatingObject.isRolling  = false;
            AudioSource.PlayClipAtPoint(sinkingSound, transform.position);
        }

        if (transform.position.y < -5.0f)
        {
            // The ship has sunk. Game over!
        }
    }