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); }
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)); } } }