// FixedUpdate is called on fixed intervals, Use for regular updates such as physics void FixedUpdate() { // Is unit supposed to move if (flag_isMoving) { // Is unit on the Destination if (transform.position.Equals(UnitDestination)) { //Unit does not move anymore flag_isMoving = false; } // If unit is not on Destination, Move else { // Vector will do a linear interpolation between our current position and our destination Vector3 v; v = Vector3.Lerp(transform.position, UnitDestination, Time.fixedDeltaTime * UnitSpeed); // set our position to the new destination transform.position = v; } } if (UnitHP <= 0) { Destroy(this.selectHighlight); Destroy(this.gameObject); MapRulesTemplate MapObject = FindObjectOfType <MapRulesTemplate>(); MapObject.RemoveUnitList(this); } }
// Use this for initialization void Start() { //Set destination as the starting location to keep unit still UnitDestination = this.transform.position; //Set variables (10 = default) /*UnitHP = 10; * UnitEnergy = 10; * UnitArmor = 10; * UnitSpeed = 10; * UnitTeam = 0; * UnitReloadSpeed = 500.0f; * Timer_Shooter = 0; * UnitSearchRadius = 15f; * UnitReloadSpeed = 5.0f; * target_distance = -255; * next_distance = -255;*/ //Find and update Unit List of the map MapRulesTemplate MapObject = FindObjectOfType <MapRulesTemplate>(); MapObject.UpdateUnitList(this); }