/// <summary>
    /// Applies damage to the player. Will finish the game if health has depleted
    /// </summary>
    /// <param name="damage">Damage to apply. Needs to be a positive value</param>
    public void applyDamage(int damage)
    {
        if (PhotonNetwork.IsConnected && !photonView.IsMine)
        {
            return;
        }

        if (damage <= 0)
        {
            Debug.LogWarning(string.Format("Unable to apply negative damage! (Value = {0})", damage));
            return;
        }

        m_health = Mathf.Max(m_health - damage, 0);
        if (m_health <= 0)
        {
            m_canSpawnMonsters = false;
            m_canUseAbilities  = false;

            // We lost all our health. The opponent wins!
            // TODO: Call function for master client to handle
            int winnerId = PhotonNetwork.IsConnected ? remotePlayer.m_id : -1;
            GameManager.manager.finishMatch(TDWinCondition.OutOfHealth, winnerId);
        }
        else
        {
            GameManagerCosmetics.playGoalHurtSound(m_id);
        }

        // Call this regardless
        if (onDamaged != null)
        {
            onDamaged.Invoke(this, damage, m_health);
        }
    }
Beispiel #2
0
    /// <summary>
    /// Easy access for playing a goal hurt sound for a specific board
    /// </summary>
    /// <param name="boardId"></param>
    public static void playGoalHurtSound(int boardId)
    {
        GameManagerCosmetics cosmetics = GameManager.getCosmetics();

        if (cosmetics)
        {
            if (PhotonNetwork.IsConnected)
            {
                cosmetics.photonView.RPC("goalHurtRPC", RpcTarget.All, boardId);
            }
            else
            {
                cosmetics.goalHurtRPC(boardId);
            }
        }
    }
Beispiel #3
0
    private GameManagerCosmetics m_cosmetics;           // Cached cosmetics component

    void Awake()
    {
        if (manager)
        {
            Debug.LogError("GameManager has already been set!");
            return;
        }

        manager = this;

        // PlayerController will set this reference upon start
        // (This will also handle proper start for play in editor)
        if (!PlayerController.localPlayer)
        {
            if (!string.IsNullOrEmpty(m_playerPrefab))
            {
#if UNITY_EDITOR
                // Check if prefab set is actually for a player controller
                GameObject controllerObject = Resources.Load(m_playerPrefab) as GameObject;
                if (!controllerObject || controllerObject.GetComponent <PlayerController>() == null)
                {
                    Debug.LogWarning("Player Prefab set is not of a player controller!");
                }
                else
#endif
                {
                    PhotonNetwork.Instantiate(m_playerPrefab, transform.position, Quaternion.identity);
                }
            }
        }

        m_cosmetics = GetComponentInChildren <GameManagerCosmetics>();
        if (!m_cosmetics)
        {
            Debug.LogWarning("No cosmetics has been attached to game manager!");
        }

        // Wait for all players to connect before starting,
        // this component will destroy itself once the match has started
        gameObject.AddComponent <GameStartHandler>();
    }