Search Unity

  1. We want you to join us at GDC this year! Take a peek at all of the events we will be hosting during the week of GDC.
    Dismiss Notice
  2. Tell us about your experience here and you’ll get early access to the 2018 Game Studios report + more goodies.
    Dismiss Notice
  3. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  5. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice

C# - How change public speed by touching touchscreen!

Discussion in 'Scripting' started by ppddgg, Jul 1, 2012.

  1. ppddgg

    ppddgg

    Joined:
    Jun 24, 2012
    Posts:
    6
    Hi! I'm a little newbe. I'm trying to understand the basics of c# in unity.
    My problem is that I want to change speed value by touching the touchscreen. This is a c# code that I tried to do.
    Can someone help me please?

    Code (csharp):
    1. public  float speed = 1;
    2.    
    3.    
    4.     void Update () {
    5.         transform.Translate(0,-speed,0);
    6.            
    7.     if(Input.touchCount == 1  Input.GetTouch(1).phase == TouchPhase.Began){
    8.             speed = 2;
    9.         }