private void OnClick() { // Check if the cooldown of the lever is ready if (resource.getDelay() <= 0.0f) { // Add the resource value to the time/scale of the pressure bar resource.AddResourceValue(); if (resource.getResourceScale() >= maxVal) { // Clamp to max value if greater // Also clamp the needle to the max pressure value resource.setResourceScale(maxVal); pressureNeedle.transform.rotation = Quaternion.AngleAxis(0.0f, new Vector3(0.0f, 0.0f, 1.0f)); } else { // Calculate the precentage of the added time/scale over 180 // Then rotate the needle to the correct added value float percentage = ((180 * resource.getResourceScale()) / 100); pressureNeedle.transform.eulerAngles = new Vector3(0.0f, 0.0f, (percentage - 180)); } } }
private void Start() { resource = this.GetComponent <scr_Resource>(); button.onClick.AddListener(OnClick); maxVal = 100.0f; resource.setResourceScale(maxVal); resource.setRescourceValue(25.0f); resource.setDelay(2.5f); // Get the speed of the needle based of 180 degrees over the time/scale of the pressure bar speed = 180 / resource.getResourceScale(); }
private void Start() { // Find resource class refenece resource = this.GetComponent <scr_Resource>(); healthBar[0] = GameObject.Find("Health1").GetComponent <Image>(); healthBar[1] = GameObject.Find("Health2").GetComponent <Image>(); healthBar[2] = GameObject.Find("Health3").GetComponent <Image>(); button.onClick.AddListener(OnClick); //Testing values resource.setResourceScale(100.0f); resource.setDecayModifier(5.0f); resource.setRescourceValue(16.6f); resource.setDelay(5.0f); percentage = resource.getResourceScale() / (healthBar.Length * 2); }
// Update health bar private void UpdateHealth() { // Need to change from hardcoded (temp) if (resource.getResourceScale() >= (percentage * 5) && resource.getResourceScale() <= (percentage * 6)) { healthBar[2].sprite = fullHealth; } else if (resource.getResourceScale() >= (percentage * 4) && resource.getResourceScale() <= (percentage * 5)) { healthBar[2].sprite = halfHealth; } else if (resource.getResourceScale() >= (percentage * 3) && resource.getResourceScale() <= (percentage * 4)) { healthBar[2].sprite = blank; healthBar[1].sprite = fullHealth; } else if (resource.getResourceScale() >= (percentage * 2) && resource.getResourceScale() <= (percentage * 3)) { healthBar[1].sprite = halfHealth; } else if (resource.getResourceScale() >= (percentage) && resource.getResourceScale() <= (percentage * 2)) { healthBar[1].sprite = blank; healthBar[0].sprite = fullHealth; } else if (resource.getResourceScale() >= 0.0f && resource.getResourceScale() <= (percentage)) { healthBar[0].sprite = halfHealth; } else if (resource.getResourceScale() <= 0.0f) { healthBar[0].sprite = blank; } }