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

Stopping Vector3 from moving

Discussion in 'Scripting' started by FalconJ, Mar 16, 2015.

  1. FalconJ

    FalconJ

    Joined:
    Mar 12, 2015
    Posts:
    146
    I have this function to move my game object :
    Code (CSharp):
    1. void Update () {
    2.         transform.position += Vector3.up * LevelManager._speed * Time.deltaTime;
    3.     }
    I have the trigger set and working but now I want that object to stop moving when it hits the trigger.

    Any idea how?
     
  2. gamer_boy_81

    gamer_boy_81

    Joined:
    Jun 13, 2014
    Posts:
    169
    You can declare a bool and set that bool to true when you hit the trigger
    and in Update(), just run your move code when the bool
    is false.
     
    FalconJ likes this.
  3. FalconJ

    FalconJ

    Joined:
    Mar 12, 2015
    Posts:
    146
    You're correct. Thank you!