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
  4. Dismiss Notice

Why isn't transform.position working?

Discussion in 'Editor & General Support' started by ChunderSon, Aug 21, 2020.

  1. ChunderSon

    ChunderSon

    Joined:
    Aug 21, 2020
    Posts:
    4
    transform.position isn't working.
    Here's the code
    void Update()
    {

    if (Input.GetKeyDown(KeyCode.R))
    {

    transform.position = new Vector3(0, 1, 0);
    }
    }

    What i am intending for the code to do is to whenever i press r it goes to the position 0, 1, 0
     
  2. ChunderSon

    ChunderSon

    Joined:
    Aug 21, 2020
    Posts:
    4
    in the text it looks like the if then sentence isn't in the void update function but i assure you in unity it is
     
  3. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    What "isn't working"? Does it print an error, not compile, or just not seem to do anything?

    Add Debug.Log() calls inside your if condition to verify that that line of code is executing. If it is not, add a Debug.Log call in the Update function to verify that your script is running.
     
  4. ChunderFam

    ChunderFam

    Joined:
    Aug 21, 2020
    Posts:
    3
    The script is running. In fact the input.getkeydown script is running because i put the debug log in that code. Its the transform.pos that isn't working which means it isn't doing anything
     
  5. ChunderSon

    ChunderSon

    Joined:
    Aug 21, 2020
    Posts:
    4
    Nevermind i figured it out. The gameObject i was trying to apply it to already has a bajillion move functions applying to it and i think they cancelled the transform.pos code
     
    Last edited: Aug 21, 2020