Transform.Position not working

Looking to make a specific gameobject be set to active and move to a specific position for an OnClick function. Everything works except the Transform.Position, as soon as I try to implement it, the Gameobject, which ordinarily is set to active OnClick, actually just completely disappears.

For context, the gameobject is ordinarily positioned at -278, 742, 0. And needs to move to -253, 483, 0 when the script runs it’s if statement and finds the bool to be true. It’s a 2D project, so I don’t actually need to use Vector3, but in all the examples I’ve found, it just seems to be the staple everyone is using regardless. Changing the Z value doesn’t change anything as far as visibility is concerned.

I’m not really sure what I’m doing wrong here. I’m sure that the solution is going to be really stupidly simple, or completely out of my league, haha, so any help would be appreciated.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;

public class isActive : MonoBehaviour
{
	
	bool Home = true;
	public GameObject YouAreHere;
	public Button DeactivatedButton;
	public GameObject ToMove;

	
    // Start is called before the first frame update
    void Start()
    {
        if(Home == true)
		{
			Debug.Log("You're at home already!");
			YouAreHere.SetActive(true);
			DeactivatedButton.interactable = false;
			ToMove.transform.position = new Vector3(-253f, 483f, 0f);
		}
		else
		{
			Debug.Log("Well, look at that, you aren't at home!");
			YouAreHere.SetActive(false);
			DeactivatedButton.interactable = true;
		}
    }

Answering my own question here. transform.localPostion is what solved it. From the research I did, I didn’t think transform.localPosition would work because what I was trying to move wasn’t a child to the parent I was moving it to.

Thank you for the couple of you that tried to help! Next time I think I’ll just try all the options that I assume won’t work before asking a question here haha.

hello, i’ll ask and explain :


Is there no update position for ToMove except here? cause it just on start then maybe you update in some where else.


And are you positioning by local position of Gameobject or not? the better do to change position like that maybe just use Gameobject pos to gameobject pos (i mean you make anchor with other object that do not have meshes or something like that), cause when you drop that hard code value ( new Vector3(-253f, 483f, 0f);), you still focus on Gameobject wich the gameobject is under of other Gameobject (it’s have a parent), so it will not showing real position/world position, it’s showing local position.


Hope it help.

First of all, since you work in a 2D space you can use a Vector2D. You can move it by changing positition over time by using a coroutine. Unity - Manual: Coroutines