- Home /
 
               Question by 
               Nawaz_ · Dec 02, 2021 at 03:15 PM · 
                scripting problemendless runnerracingracing game  
              
 
              How do I make the Road move faster when I click with left mouse button?
I am making an 2D endless racing game in which the road is moving by default, but I want to make the road move faster when I click with leftmousebutton so It would seem like the car is boosted.
(offset is of the road texture which is on a Quad).
 public class RoadMove : MonoBehaviour
 {
     public float speed;
     Vector2 offset;
 
     void Update()
     {
         offset = new Vector2(0, Time.time * speed);
         GetComponent<Renderer>().material.mainTextureOffset = offset;
     }
 }
Can someone help me with this ?
Thanks
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by gipsnichmeer · Dec 02, 2021 at 05:23 PM
Just use a different speed factor when you want to boost.
Like this:
  public class RoadMove : MonoBehaviour
  {
      public float speed;
      public float boostedSpeed;
      Vector2 offset;
  
      void Update()
      {
          if(Input.GetMouseButton(0)) //Mouse button 0 is left mouse button
              offset = new Vector2(0, Time.time * boostedSpeed);
          else
              offset = new Vector2(0, Time.time * speed);
          
          
          GetComponent<Renderer>().material.mainTextureOffset = offset;
      }
  }
Your answer
 
 
             Follow this Question
Related Questions
How do I make the winning racer get a text saying Congrats? 1 Answer
Endless runner 2 Answers
How to make the ball rotate 0 Answers
Anti-Gravity Hovercraft Racing (Physics) 1 Answer
Car exhaust Flame in unity 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                