// Called on the frame this script is enabled, before Update(). private void Start() { fireTimer = fireRate; reloadTimer = reloadSpeed; inicialPosition = transform.parent.localPosition; weaponIndex = GetWeaponIndex(); playerAmmo = GameObject.Find("Ammo").GetComponent <Text>(); animator = localNetworkUser.GetComponent <Animator>(); networkCallback = localNetworkUser.GetComponent <NetworkCallback>(); }
// 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); } } }
// 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(); } }