Martin j
Martin j

Reputation: 521

how to increase the speed of the runner when a powerup shoe is picked

if (Collision.ShoeIndicator)
        {
            GameObject p = GameObject.FindGameObjectWithTag ("Player");

            Vector3 t = p.transform.position;

            t.z = powerUpSpeedIncrease1 * Time.deltaTime;

            p.transform.position = t;
        }

for powerUpSpeedIncrease1 i have set 10.0

here my player is an infinite runner when the powerup is picked i need to increase the speed of the player,this code is actually false...how can i increase the speed

i have used a timer to set the time period for this powerup

 if(timeleft <= 0)
            {
                //Collision.coinMag = false;
                Collision.ShoeIndicator = false;
                timeleft = 10;
            }

Upvotes: 0

Views: 443

Answers (1)

Amir Rasulov
Amir Rasulov

Reputation: 141

You should add

 transform.position *= powerUpSpeedIncrease1;

where you set the new position of the player and set the

 powerUpSpeedIncrease1 = 1;

when player is not using speedup boost or time of using boost is finished and set the

 powerUpSpeedIncrease1 = 10;

when boost is picked up

In your code it will look like

if (Collision.ShoeIndicator)
{
  Collision.ShoeIndicator = false; //you can pickup new shoe when you also picked up one
  powerUpSpeedIncrease1 = 10;
  //timeleft = 10;{timer code setting up} 
  //dont forget about the scope! 
  //powerUpSpeedIncrease1 should be available in your playercontroller or 
  //where you controlling player's position
}

if(timeleft <= 0)
{
   powerUpSpeedIncrease1 = 1;
}

update() {
   //decrease timer
}

p.s. timer example

Upvotes: 1

Related Questions