Example #1
0
    // Update is called once per frame
    void Update()
    {
        dashStacks = (int)energy;               //creates a round number of stacks based on the energy

        //set speed and goal for dashing & subtract from dash counter
        if (swipeCont.dashing)
        {
            currentSpeed   = dashSpeed;
            target         = swipeCont.dashGoal;
            dashRemaining -= Time.deltaTime;
        }

        //set speed and goal for walking and reset combo counter
        if (swipeCont.walking)
        {
            currentSpeed     = walkSpeed;
            target           = swipeCont.walkGoal;
            combo.killStacks = 0;
        }

        Move();

        //energy regeneration and ceiling
        if (energy < maxEnergy)
        {
            energy += energyReg;
        }
        else
        {
            energy = maxEnergy;
        }

        //stop dash if counter expires or goal is reached
        if ((dashRemaining <= 0) || (transform.position == swipeCont.dashGoal))
        {
            swipeCont.StopDashing();
            dashRemaining = dashDistance;
        }

        //update energy UI
        energyBar.GetComponent <RectTransform> ().localScale = new Vector3(1, energy / maxEnergy, 1);
    }