Hello, I am unsure whether or not I should change my codes around because computation or whatever might get gobbled up because of the update is checking something. In my game I am trying to scale a game object that is a bar of energy in the update method that constantly adds .5 increments. And within the update method is an if statement that if the ‘energy’ were to pass 100, the new energy value becomes 100. But the increments continues to add .5 to the already existing 100 so it goes back to the 100 value once its passed 100. I feel this to be like a vicious cycle of checks that takes up computer computation/compiling or whatever.
I’ve looked up the documentation about update and fixed update and the only difference I could pick up was that fixedupdate has more to do with physics and rigidbody.
Here is the code so that it would be easier to see what I am talking about:
using UnityEngine;
using System.Collections;
public class AlternateAttackProtocol : MonoBehaviour
{
private static AlternateAttackProtocol instance = null;
public static AlternateAttackProtocol Instance
{
get {return instance; }
}
public Transform alternateAttackDisplay;
public float maxAlternateAttack = 100.0f;
public float currentAlternateAttack;
private float alternateAttackOriginalXScale;
private GameObject player;
void Start ()
{
alternateAttackOriginalXScale = alternateAttackDisplay.localScale.x;
currentAlternateAttack = 0.0f;
player = GameObject.FindGameObjectWithTag ("PlayerCharacter");
}
void Update ()
{
currentAlternateAttack = currentAlternateAttack + 0.5f;
if(currentAlternateAttack >= 100)
{
Debug.Log("Being Accessed");
currentAlternateAttack = 100;
}
if (currentAlternateAttack <= 100 && Input.GetButtonDown ("Fire2"))
{
currentAlternateAttack = 0.0f;
player.SendMessage ("ShootAlternativeStandBy", true);
Debug.Log ("AlternateAttackButton has been Reached");
}
alternateAttackDisplay.localScale = new Vector3(alternateAttackOriginalXScale * (currentAlternateAttack/maxAlternateAttack), alternateAttackDisplay.localScale.y, alternateAttackDisplay.localScale.z);
}
}
This has been bothering due to me not wanting to have a game that has performance issues. If anyone can shed some light on this that would be awesome. And Thanks.