コード例 #1
0
    void Start()
    {
        // First, if there are multiple canvas' within the player object...
        // then we must find the one with the "HUD" tag
        List <int> arrayIndexes     = new List <int>();
        var        canvasComponents = GetComponentsInChildren <Canvas>();

        for (int i = 0; i < canvasComponents.Length; i++)
        {
            if (canvasComponents[i].CompareTag("HUD"))
            {
                // Remember the array index so that we can directly modify
                // the canvas that has the "HUD" tag
                arrayIndexes.Add(i);
                //hudCanvas = canvasComponents[i];
            }
        }

        foreach (int arrayIndex in arrayIndexes)
        {
            // By default, disable the HUD Canvas if the developer forgets to disable in the Unity editor
            GetComponentsInChildren <Canvas>()[arrayIndex].enabled = false;

            if (isLocalPlayer)
            {
                DevLog.Log("LocalCanvas", "Enable UI for LocalPlayer netId: " + GetComponent <NetworkIdentity>().netId);
                // Enable the HUD UI canvas for our local player instance. This will ensure
                // that other player UIs will never overlap with the host or other clients...
                GetComponentsInChildren <Canvas>()[arrayIndex].enabled = true;
            }
        }
    }
コード例 #2
0
    public void DealDamageToEnemy(GameObject otherObject)
    {
        GameObject player = NetworkServer.FindLocalObject(ownerId);

        damageRate = player.GetComponent <PlayerStats>().Damage;
        DevLog.Log("Bullet", "Player with id <" + ownerId.ToString() + "> dealt damage to enemy with " + damageRate);
        otherObject.GetComponent <Health>().EnemyTakeDamage(damageRate, ownerId);
    }
コード例 #3
0
    /// <summary>
    /// Methods occurs when player's health reaches/is zero.
    /// </summary>
    void OnPlayerHealthZero()
    {
        DevLog.Log("Health", "The player health is zero... Changing color... syncing");

        // Change the color of the player to reflect their "dead" state
        GetComponentInChildren <MeshRenderer>().material.color = Color.red;

        // By setting the "isAlive" bool to false, we trigger
        // the SyncVar hook in the CharacterState
        thePlayer.status = CharacterStatus.RESCUE;
    }
コード例 #4
0
    public void TakeDamage(float amount)
    {
        if (!isServer)
        {
            return;
        }

        currentHealth -= amount;
        if (currentHealth <= 0.0f)
        {
            currentHealth = 0.0f;
            RpcOnPlayerDead();
            DevLog.Log("Health", "Player id <" + GetComponent <NetworkIdentity>().netId + "> is dead...");
        }
    }
コード例 #5
0
    void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            // If the PLAYER i encounter is in a "RESCUE" state, therefore
            // it means that i can attempt to revive the other person...
            if (playerToRescue != null && playerToRescue.characterState.status == CharacterStatus.RESCUE)
            {
                // DEBUG
                targetId = other.GetComponent <NetworkIdentity>().netId;

                // When PLAYER1 (myself) enters the revive zone, we want to show the revive ui box
                rescueButton.gameObject.SetActive(false);

                DevLog.Log("ReviveTrigger", "Player id <" + myNetId + "> exited vicinity of <" + targetId.Value + ">");
            }
        }
    }
コード例 #6
0
    void CmdRescueButtonOnClick()
    {
        if (playerToRescue != null)
        {
            //DevLog.Log("ReviveTrigger", "Player id <" + myNetId + "> attempting to revive <" + this.playerToRescue.tmpNetworkId + ">");

            try
            {
                // Tell the server to RESCUE the downed player by restoring their health and their character appearance
                playerToRescue.CmdOnPlayerRescue();
            }
            catch (Exception ex)
            {
                string error = ex.Message;
                DevLog.Log("ReviveTrigger", "Exception thrown. Ignoring because player is already revived.\n" + error);
            }

            RpcSetRevivePanelActive(false);
        }
    }
コード例 #7
0
 void OnDisable()
 {
     DevLog.Log("ReviveTrigger", "OnDisable executing");
     rescueButton.onClick.RemoveListener(delegate { CmdRescueButtonOnClick(); });
 }
コード例 #8
0
 public override void OnServerConnect(NetworkConnection conn)
 {
     DevLog.Log("NetworkManagerCustom", "Someone connected to the server: " + conn.connectionId);
 }
コード例 #9
0
 void OnChangeStatus(CharacterStatus status)
 {
     DevLog.Log("CharacterState", "Player id <" + GetComponent <NetworkIdentity>().netId + "> status = " + status.ToString());
     this.status = status;
 }