Question by
unity_IqSOm45N2ffN3g · Aug 22, 2020 at 11:58 AM ·
movingmovinggameobjectdissapear
moving object dissapears when it reaches it's destination
so I have an object that is supposed to move between two empty game object's transform.
public class MoveOntheSpot : MonoBehaviour { public Transform pos1, pos2, pos3; public float speed; public Transform startPos;
Vector3 nextPos;
// Start is called before the first frame update
void Start()
{
nextPos = startPos.position;
}
// Update is called once per frame
void Update()
{
if (transform.position == pos1.position)
{
nextPos = pos2.position;
}
if (transform.position == pos2.position)
{
nextPos = pos3.position;
}
if (transform.position == pos3.position)
{
nextPos = pos1.position;
}
transform.position = Vector3.MoveTowards(transform.position, nextPos, speed * Time.deltaTime);
}
private void OnDrawGizmos()
{
Gizmos.DrawLine(pos1.position, pos2.position);
}
}
It moves very slowly to the first position and when it hits the first position it suddenly dissapears from the players view.(I can still see it moving normally in the scene view)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613010248im_/https://answers.unity.com/themes/thub/images/avi.jpg)