I have a GameObject that I try to move. For the GameObject I created a new class and this class has a function UpdatePosition(). In this function I update the transform.position of the GameObject and if I log the transform.position of the object, the console writes the newly updated position. However, in the game and scene view in Unity the object does not move. I call the function every tick via an Update function and this works since the Debug.Log outputs to the console every tick. Does anyone know what is going wrong here?
public class ActiveObjects
{
[SerializeField]
public GameObject theMovingObject;
[SerializeField]
public Transform startPosition;
[SerializeField]
public Transform endPosition;
[NonSerialized]
private float speed = 10.0f;
[NonSerialized]
public float startTime;
[NonSerialized]
public float journeyLength;
// Sets new position of theMovingObject
public void UpdatePosition()
{
float step = speed * Time.deltaTime;
theMovingObject.transform.position = Vector3.MoveTowards(theMovingObject.transform.position, endPosition.position, step);
Debug.log(theMovingObject.transform.position);
}
}
The output of in the console is the position which theMovingObject should have, but does not have in the game/scene view.
MonoBehaviour, so this class isn't attached to any game object. Care to show how and from where you callUpdatePosition()? - Galandil