Esempio n. 1
0
 void OnEnable()
 {
     cooldownTimer = cooldown;
     if (body != null)
     {
         body.velocity = Vector2.zero;
     }
     if (touches != null)
     {
         prevTouch = touches.GetLastTouch();
     }
 }
 void FixedUpdate()
 {
     direction = TouchDirection(touches.GetLastTouch());
     if (direction == Vector2.right)
     {
         if (body.velocity.x < maxSpeed)
         {
             if ((body.velocity += direction * acceleration * Time.fixedDeltaTime).x > maxSpeed)
             {
                 body.velocity = new Vector2(maxSpeed, body.velocity.y);
             }
         }
     }
     else if (direction == Vector2.left)
     {
         if (body.velocity.x > -maxSpeed)
         {
             if ((body.velocity += direction * acceleration * Time.fixedDeltaTime).x < -maxSpeed)
             {
                 body.velocity = new Vector2(-maxSpeed, body.velocity.y);
             }
         }
     }
 }