x


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?

more ▼

asked Aug 16 '10 at 03:56 PM

Mattivc gravatar image

Mattivc
1.7k 55 60 67

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

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);
        }
    }
}
more ▼

answered Mar 28 '11 at 03:12 PM

Jordan Miller 2 gravatar image

Jordan Miller 2
348 47 51 57

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3130
x2175
x278

asked: Aug 16 '10 at 03:56 PM

Seen: 1541 times

Last Updated: Aug 16 '10 at 03:56 PM