// Called every frame after Start(). private void Update() { if (localPlayer == null) { // Look for our local Player. foreach (GameObject player in GameObject.FindGameObjectsWithTag("Player")) { NetworkUser networkUser = player.GetComponent <NetworkUser>(); if (networkUser.isLocalPlayer) { localPlayer = networkUser; playerInventory = localPlayer.GetComponent <PlayerInventory>(); return; } } } else { beingInteracted = (localPlayer.currentTarget == gameObject); } // If we press the interact button and we were interacting with this item, attempt to buy it. if (Input.GetButtonDown("Interact") && beingInteracted) { if (localPlayer.currency >= itemPrice) { // Charge the player and equip the new item over the Network. localPlayer.CmdUpdateCurrency(itemPrice, true, true); playerInventory.CmdAddItem(itemName, (int)itemType); } } }
// Will reward the Player with the NetworkInstanceID equal to <shooterID> that killed this Zombie. private void RewardPlayer(NetworkInstanceId shooterID) { foreach (GameObject player in GameObject.FindGameObjectsWithTag("Player")) { NetworkUser networkUser = player.GetComponent <NetworkUser>(); // If we found the Player with <shooterID>, then reward him. if (networkUser.netId == shooterID) { if (currentHealth <= 0f) { // If he killed us, add to his kills and give him the <deadReward>. networkUser.CmdUpdateKills(); networkUser.CmdUpdateCurrency(deathReward, false, false); } else { // If he damaged us, give him the <damageReward>. networkUser.CmdUpdateCurrency(damageReward, false, false); } } } }
// Called every frame after Start(). private void Update() { GetComponent <UnityEngine.AI.OffMeshLink>().activated = (currentHealth == 0f); if (localPlayer == null) { GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); // Find our Player GameObject inside the Scene and retrieve its data. foreach (GameObject player in players) { NetworkUser networkUser = player.GetComponent <NetworkUser>(); if (networkUser.isLocalPlayer) { localPlayer = networkUser; break; } } } else { // Check if the current interaction target from the player is us. beingInteracted = (localPlayer.currentTarget == gameObject); } // If we are no longer repairing this barricade, reset the repair timer. if (isRepairing) { infoUI.Find("Barricade Text").GetComponent <Text>().text = string.Format("Repairing... {0}%", Mathf.Floor(repairPercentage)); GetComponent <Interactable>().interactStatus = Interactable.InteractStatus.NonStatic; } if (beingInteracted) { // If this barricade is being interacted and there is planks to repair. if (Input.GetButton("Interact") && destructionCounter > -1) { isRepairing = true; repairTimer += Time.deltaTime; repairPercentage = ((repairTimer / repairRate) * 100f); if (alphaCloneRenderer != null) { plankColor.a = Mathf.Lerp(0f, 1f, repairPercentage / 100f); alphaCloneRenderer.material.color = plankColor; } // Prevents stacking sounds ontop of each other. if (soundTimer >= repairSound.length) { // Play the repair sound over the Network. localPlayer.GetComponent <NetworkCallback>().CmdPlayRepairSound(gameObject); soundTimer = 0f; } else { soundTimer += Time.deltaTime; } if (repairTimer >= repairRate) { // Repair the destroyed plank over the Network. localPlayer.GetComponent <NetworkCallback>().CmdRepairPlank(gameObject); // Give the Player who repaired the Barricade the <repairReward>. localPlayer.CmdUpdateCurrency(repairReward, false, true); repairTimer = 0f; } } else if (isRepairing) { StopRepair(); } } else if (isRepairing) { StopRepair(); } }