void Update() { for (int i = 0; i < healthBar.Length; i++) { for (int j = 0; j < fillColor.Length; j++) { healthBar[i].value = playerMovement.currentHP; healthBar[i].maxValue = playerMovement.maxHP; if (healthBar[i].value <= 100 && healthBar[i].value >= 76) { fillColor[j].color = excellent; } else if (healthBar[i].value <= 75 && healthBar[i].value >= 51) { fillColor[j].color = good; } else if (healthBar[i].value <= 50 && healthBar[i].value >= 26) { fillColor[j].color = medium; } else if (healthBar[i].value <= 25) { fillColor[j].color = bad; } } } for (int i = 0; i < healthValue.Length; i++) { healthValue[i].text = playerMovement.currentHP.ToString(); } for (int i = 0; i < medKitAmount.Length; i++) { medKitAmount[i].text = playerMovement.playerAttr.amountOfMedKits.ToString(); } for (int i = 0; i < gunName.Length; i++) { for (int j = 0; j < ammoCount.Length; i++) { if (playerMovement.gunEquipped != null) { weaponsBehaviour = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerMovement>().gunEquipped.GetComponent <WeaponsBehaviour>(); gunName[i].text = weaponsBehaviour.weaponName; gunName[i].fontSize = 18f; ammoCount[j].enabled = true; ammoCount[j].text = weaponsBehaviour.clipSize + " / " + weaponsBehaviour.maxAmmo; } else { gunName[i].text = ""; ammoCount[j].enabled = false; } } } }
void Update() { if (playerAttr.currentHP <= 0) { playerAttr.isDead = true; playerAttr.currentHP = 0; } if (playerAttr.currentHP > playerAttr.maxHP) { playerAttr.currentHP = playerAttr.maxHP; } if (!playerAttr.isDead) { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveVertical, 0, -moveHorizontal); m_rigidbody.velocity = movement * playerAttr.walkSpeed; if (Input.GetKeyDown(KeyCode.W)) { m_animator.SetFloat("xPos", 0); m_animator.SetFloat("yPos", 1); } if (Input.GetKeyDown(KeyCode.S)) { m_animator.SetFloat("xPos", 0); m_animator.SetFloat("yPos", -1); } if (Input.GetKeyDown(KeyCode.D)) { m_animator.SetFloat("xPos", 1); m_animator.SetFloat("yPos", 0); } if (Input.GetKeyDown(KeyCode.A)) { m_animator.SetFloat("xPos", -1); m_animator.SetFloat("yPos", 0); } if (gunEquipped != null) { weaponsBehaviour = gunEquipped.GetComponent <WeaponsBehaviour>(); if (Input.GetKeyDown(KeyCode.Space) && weaponsBehaviour.clipSize > 0) { weaponsBehaviour.StartCoroutine("Shoot"); } if (Input.GetKeyDown(KeyCode.Q)) { gunEquipped.transform.parent = null; gunEquipped = null; } } if ((Input.GetKeyDown(KeyCode.F)) && (playerAttr.amountOfMedKits >= 1 && playerAttr.currentHP < 100)) { playerAttr.currentHP += 20; playerAttr.amountOfMedKits -= 1; if (playerAttr.currentHP > 100) { playerAttr.currentHP = 100; } } } }