- Home /
gameObject.renderer.isVisible = false for one frame after activation
Im working on a function to reset projectiles when they move off camera in my 2D iPhone space shooter. The function is called every frame.
function ResetOutOfBoundsProjectiles() // Resets projectile outside of the render area.
{
for(i=0; i<maxNumProjectiles; i++)
{
if(projectilesArray[i].active == true && !projectilesArray[i].renderer.isVisible)
{
projectilesArray[i].active = false;
projectilesArray[i].transform.position = projectileIntPosition;
projectilesInUse--;
}
}
}
The problem i am having is that it seems the renderer.isVisible function seems to return false for one frame after is has been enabled, adfter the first frame it returns true as expected. This causes the projectile to be immediately reset the same frame its enabled. The weird thing is that this function worked perfectly earlier. Do anyone know why the gameobject would return false on renderer.isVisible on the first frame, and how i can fix it?
Answer by Jordan Miller 2 · Mar 28, 2011 at 03:12 PM
why not just use OnBecameInvisible?
var projectileIntPosition = ???; var somemanagerobject : GameObject;
function OnBecameInvisible() //ResetThisOutOfBoundsProjectile() // Put this script on each projectile (on the prefab) { if(gameObject.active) { gameObject.active = false; gameObject.transform.position = projectileIntPosition; somemanagerobejct.getComponent(managerScript).SetUsedProjectiles(-1); } } }
Your answer
Follow this Question
Related Questions
Planes and other Gameobjects disppear as I dolly/rotate the camera and in render mode 0 Answers
Make Camera not render individual GameObject? 1 Answer
Gameobject to stay within the view of the camera - c# 3 Answers
Light glitch when not in camera's view 0 Answers
Making a game object un-render or turn-invisible through trigger? 1 Answer