- Home /
Relocate GameObject when location is triggered
Hi guys, I'll start by saying I'm very new to scripting, but really enjoying it and want to get my head around it.
In my scene, I have an object moving in the x-axis at a constant rate, and moving up and down the y-axis as controlled by the player. I would like to reset the position of the object when it reaches 90 units in the x-axis. I am having some trouble with this, but my current attempt is this:
public void Update()
{
if (gameObject.transform.position == new Vector3(90, gameObject.transform.position.y, gameObject.transform.position.z))
{
}
}
So the object can be "located" when its x-position is 90, I put the position of the game object in the y- and z- places in that Vector3. I would then have the function run another function to reset the position of the object. I have no idea if I'm on the right track here, so any help is appreciated.
If you need more info, let me know. And if there are other questions/answers on this forum that are similar, I apologise - I've been searching for hours for a solution with no success.
Thanks!
The chances of hitting an integer value with a float are quite remote.
if(transform.position.x >= 90.0)
Ahh wonderful! As embarrassing as it is, I didn't even think of that. Thanks :)