Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity 2D sample character controller : How can I increase speed by 1% each second?

Discussion in 'Scripting' started by s3king93, May 8, 2014.

  1. s3king93

    s3king93

    Joined:
    May 8, 2014
    Posts:
    13
    Hey everybody, so I'm making my first game in unity. I'm using the sample 2d character controller to make an infinite runner and I'd like to increase the players speed by 1% each second.

    Currently I'm using


    Code (csharp):
    1. public float maxSpeed = 10f;                // The fastest the player can travel in the x axis.
    2.     [SerializeField] float jumpForce = 400f;           
    3.         private float increaseAmount = 0.01f;
    4.  
    5.  
    6.    
    7.  
    8.     void OnGUI()
    9.     {
    10.         GUI.Label(new Rect(10, 20, 150, 30), "Speed: " + (float)(this.maxSpeed));
    11.     }
    12.  
    13.     void start(){
    14.         InvokeRepeating("IncreaseSpeed", 1, 1);
    15.     }
    16.  
    17.  
    18.     void IncreaseSpeed()
    19.     {
    20.         maxSpeed += increaseAmount;
    21.     }

    But nothing is happening, The players speed is being outputted to the GUI but no speed increase is happening.

    Anybody have any ideas?

    Help is greatly appreciated.
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    start needs to be capitalized.
     
  3. s3king93

    s3king93

    Joined:
    May 8, 2014
    Posts:
    13
    thank you!
     
  4. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    You don't increase by 1%... You increase by 0.01 m/s. Just saying.