- Home /
How do I stop a moving object when the Camera sees it
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;
}
}
Answer by FerdinandBuagas · Sep 21, 2017 at 01:48 AM
If the game object reaches the coordinates of camera then set the body type of the game object to kinematic.
In your update
a = GameObject.Find(yourGameObject).transform.position.x;
if(a< positionofyourcamera ){
yourgameobject.isKinematic = true;
}
That will somehow give you idea. :)
ps: I am new :)
Your answer
Follow this Question
Related Questions
How do I trigger the visibility of an object through OnBecame(In)visible? 0 Answers
why when my first person camera looks at to many gameobjects it becomes really sensitive? 1 Answer
How do I use OnBecameVisible and OnBecameInvisible? 2 Answers
OnBecameInvisible() Error 1 Answer
How to use isVisible or OnBecameInvisible() to detect player offscreen 1 Answer