Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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.         }