This is just a simple thing I want to do. I have my cylinder gameobject moving up and down and I want to make it so when the camera sees it, it stops moving. So, it’s not moving at all. If anything, it will move for a split second before stopping. If you could steer me in the right direction, I’d appreciate it. thank you
public class cylinderMove : MonoBehaviour, MoveObject {
public float delta = 1.5f;
public float speed = 2.0f;
private Vector3 startPos;
private bool seen = false;
public void OnBecameVisible()
{
seen = true;
}
public void OnBecameInVisible()
{
seen = false;
}
void Start()
{
startPos = transform.position;
}
void Update()
{
if (!seen)
move();
}
public void move()
{
Vector3 v = startPos;
v.y += delta * Mathf.Sin(Time.time * speed);
transform.position = v;
}
}