- Home /
How do I use an objects own coordinates within a script component placed on it and a few more questions related
I am very new to this so sorry if I'm an idiot
First off, see the title, I'm sure its simple but I have no idea.
I'm making a 2D game in which I need the player to be able to click on a tile, and then they would be moved to the middle of that tile, or exactly on the tiles coordinates and I have no idea where to start. I've tried looking it up but I can't find anything that tells me how to move an object from a different objects script and how to get the base objects coordinates inside its own script to use.
Answer by Casiell · Sep 23, 2018 at 08:51 PM
Here is an example video on moving objects. I'm still going to answer your questions (at least some of them), but it's clear you didn't really watch any tutorial and probably didn't look for any because your title question is literally a first thing you are told in basic tutorials including those on Unity official site.
Now:
To get another objects position you have to have a reference to it. You can either find it dynamically with code or you can simply create a public GameObject field and drag that other object in the inspector window. Then you can do otherGameObject.position to get it's coordinates just like with your gameObject.
To learn how to use TileSystem you should watch some tutorials, there are plenty and I would recommend CodeMonkey or Brackeys. They both have amazing tutorials and CodeMonkey even has a whole ongoing series where he teaches absolute basics of Unity
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How can i detect, that object is close to some coordinates? 1 Answer