^ Agreed, looking at your code it’s hard to tell what exactly you’re trying to do because there’s all sorts of variables that don’t seem to be serving any purpose. Your “spot” variable, for instance, is being declared in the Start function, so the scope of the variable is in the Start function- you won’t be able to see it from anywhere else. If you want, you can declare it in the class scope (like you did with x, y, and z), and then assign it a value in the start function and that’ll work fine.
Now, as for the information you’re actually looking for:
To actually achieve manual movement this way, there’s three popular methods: The first method to simply translate it from one spot to another, but that’s instant movement from point A to point B. You’ll have to do your vector and distance calculations beforehand if you want to increment it by time (free movement with WASD or a controller can work this way). The second method is to point the object at a point in space (make it look at it), and then just move the current object “forward” (toward the other object) by a rate of speed*time. This can be really useful if you set up a timer beforehand (walk toward X for 3 seconds, then stop). The third method involves the Vector3.MoveTowards function, which I especially like in cases like these because it won’t overshoot the target and start “flickering”- like a car that runs something over and then keeps reversing/accelerating to run it over again and again. If it’s going to overshoot it, it’ll just stick right to it instead.
EDIT: I hope I said something that may help you with the logic of this kind of thing, but upon looking back at the question it seems I misunderstood the problem. To answer what I now see as the actual problem, the others seem to have gotten there first. Transform.Position is actually a vector3, and as such it has 3 members called x, y, and z which are floats indicating their various positions along that axis in space. So, you just have to call transform.position.x to get the float value for x and compare it to some other value.
As TheSniperFan has stated, comparing float values is seriously annoying, and the solution he offered is only effective if you have absolute confidence that Object A is going to be getting incrementally closer to Object B. In this case, that may never happen, because overshooting your target by enough means it’ll reverse over it and overshoot it again by an equal amount- it won’t work unless the distance is being divided in some way. I think using the third approach I mentioned, the Vector3.MoveTowards() function, would be far better in this case as it avoids that kind of problem.
All of your code can be condensed to this:
using UnityEngine;
using System.Collections;
public class movingman : MonoBehaviour {
public Vector3 TargetPosition = new Vector3(200f, 1f, 200f);
float speed = 10f;
void Start(){
}
void Update(){
if(transform.position != TargetPosition)
Vector3.MoveTowards(transform.position, TargetPosition, speed * Time.deltaTime);
}
}