예제 #1
0
    // Finds the character in the submarine and activates it.
    // This method is called by the buttons on the CharacterMenu panel.
    // Using an int since button can't use enums as parameter.
    public void SetPlayerCharacter(int character)
    {
        // We deactivate the playercharacter gameobject if we already have one.
        if (_character != null)
        {
            _character.Deactivate();
        }

        switch (character)
        {
        case (int)PlayerCharacters.Driver:
            _character = _submarine.GetComponentInChildren <Driver>(true);
            break;

        case (int)PlayerCharacters.Gunner:
            _character = _submarine.GetComponentInChildren <Gunner>(true);
            break;

        case (int)PlayerCharacters.Commander:
            _character = _submarine.GetComponentInChildren <Commander>(true);
            break;
        }

        // We activate the chosen character and hide the character menu.
        if (_character != null)
        {
            _character.Submarine = _submarine;
            _character.Activate();
        }

        gameObject.SetActive(false);
    }