Search Unity

Need help with speed increase(beginner level)

Discussion in 'Getting Started' started by Jakoodza, Nov 20, 2022.

  1. Jakoodza

    Jakoodza

    Joined:
    Nov 9, 2022
    Posts:
    2
    Hello. First post here. Non EN speaker,sorry.

    Started my first project week ago( no exp with Unity or programing).

    Simple game: items falls and you need to catch them with crate bellow.

    I want to increase drop speed every 5 drops collected.



    My script:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DropMovement : MonoBehaviour
    6. {
    7.      
    8.      float dropSpeed=2f;
    9.    
    10.      public ItemCollect instCollect;
    11.        
    12.     void Start()
    13.     {
    14.         instCollect=FindObjectOfType<ItemCollect>();
    15.        
    16.      }
    17.  
    18.    
    19.     void Update()
    20.     {
    21.         transform.position = transform.position + new Vector3(0,-1,0)*dropSpeed*Time.deltaTime;
    22.         transform.eulerAngles+=new Vector3(0,0,20f*Time.deltaTime);
    23.  
    24.             if(instCollect.countCheck==5)
    25.          {
    26.              dropSpeed++;
    27.              instCollect.countCheck=0;
    28.          
    29.          }
    30.        
    31.     }

    So,every time i collect 5 items,dropSpeed increases,but its back to 2f after I reach another number.
    How can i save increased speed and not go back to default?
     
    Last edited: Nov 20, 2022
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    Welcome to the forums!

    Please only use the 2D forum for 2D related issues and not for general scripting issues, typos etc.

    I'll move your post to the Getting Started forum which is a great place to start for you. There's also a Scripting forum for general scripting issues you can use too.

    NOTE: Please use code-tags when posting code and not plain text. You can also edit your posts to include this. Also, you tagged this as 2D physics and it's not related to physics at all.
     
  3. Jakoodza

    Jakoodza

    Joined:
    Nov 9, 2022
    Posts:
    2
    Got it. Fixed the post.
     
    MelvMay likes this.