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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to make my Parallax faster with time? I know it's not hard,but i dont get it!

Discussion in '2D' started by Yeje_123, May 19, 2015.

  1. Yeje_123

    Yeje_123

    Joined:
    May 19, 2015
    Posts:
    2
    Code (CSharp):
    1. ic bool StartMoving= false;
    2.     public float SpeedScroll = 0f;
    3.     private bool Moving = false;
    4.     private float TimeStart = 0f;
    5.  
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.         NotificationCenter.DefaultCenter().AddObserver(this, "CharacterStartRunning");
    10.         NotificationCenter.DefaultCenter().AddObserver(this, "CharacterIsDead");
    11.         if (StartMoving) {
    12.             CharacterStartRunning();
    13.         }
    14.     }
    15.  
    16.     void CharacterIsDead(){
    17.         Moving = false;
    18.     }
    19.  
    20.     void CharacterStartRunning(){
    21.         Moving = true;
    22.        TimeStart = Time.time;
    23.     }
    24.  
    25.     // Update is called once per frame
    26.     void Update () {
    27.        
    28.  
    29.             if (Input.GetMouseButtonDown (0)) {
    30.                 SpeedScroll += 0.02f;
    31.  if(Moving){
    32.  
    33.             GetComponent<Renderer>().material.mainTextureOffset = new Vector2(((Time.time - TimeStart) * SpeedScroll) % 1, 0);
    34.         }
    35.     }
    36. }
    37.  
    This is how i get my Scroll moving,but i want it to move faster thru time,any help please?
    THANK YOU ALL!

    EDIT: I know how to make it faster, but when i click, it looks like the parallax "starts" again, doing an awful effect, like it cuts and starts at the beginning
     
    Last edited: May 20, 2015
  2. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
  3. Yeje_123

    Yeje_123

    Joined:
    May 19, 2015
    Posts:
    2
    Oh sorry for my mistake,done! =)