Construct.Update C# (CSharp) Method

Update() public method

public Update ( ) : void
return void
    void Update()
    {
        //If a unit has the order to construct and it is close enough to the building, start the construction
        if (construct)
        {
            //Debug.Log("Posicio unit "+transform.position);
            //Debug.Log("Posicio building " + buildingToConstruct.transform.position);
            //Debug.Log("Distancia que ha de parar " + dist + "magnitud resta " + (transform.position - buildingToConstruct.transform.position).magnitude);
            if (buildingToConstruct != null)
            {
                if ((transform.position - buildingToConstruct.transform.position).magnitude < dist + 1)
                {

                    buildingToConstruct.GetComponent<BuildingConstruction>().startConstruction(this.gameObject);

                    construct = false;
                    inConstruction = true;
                    if (usingDust == null) usingDust = Instantiate(dustPrefab, buildingToConstruct.transform.position, Quaternion.identity) as GameObject;

                    UnitMovement uM = gameObject.GetComponent<UnitMovement>();
                    if (uM != null)
                    {
                        uM.hasTarget = false;
                        Animator a = GetComponentInParent<Animator>();
                        a.SetBool("walk", false);
                        //uM.status = Status.idle;
                    }
                }
            }

        }
        if (inConstruction)
            GetComponentInParent<Animator>().SetBool("chop", true);

        if (inConstruction == false && usingDust != null)
        {

            Destroy(usingDust);
            usingDust = null;
            GetComponentInParent<Animator>().SetBool("chop", false);
        }
    }