I want to detect when my object escaped from the screen and when its escaped, i want to change scene.
This might help you.
i used
if (GetComponent<Renderer>().isVisible)
{
//Visible code here
}
else {
//Not visible code here
}
but when i start game, not visible code is executing itself two times, but my object is still visible.
I wouldn’t use that…
I think in editor it check all the cameras, which might be problematic.
And you shouldn’t probably do GetComponent in every Update… cache that to some field.
Also - when posting code, always use code tags, here is how:
You can edit you message with that edit button…
I would use this instead:
screenPos = myCamera.WorldToViewportPoint(transform.position);
Then simply check if your position is less than 0 or more than 1 in either x or y.
should i this code put to my object’s script?
“should i this code put to my object’s script?”
I didn’t give some cut and paste code… if you know the basics, you should pretty much be able to use that without much effort.
I think you should visit https://learn.unity.com/ and watch some tutorials.
You can place code where it fits best in your code. It could be in object, or in some other object depending on what you are trying to do. Which you didn’t explain to begin with.
i started using unity yesterday and i just know how to detect event when object is not visible on camera
“i started using unity yesterday”
IHMO - that is why you should watch some tutorials!
i watched but i need fast reply how to do this event