Hello All I want to make my player blink when her is his and here is my code. But i keep getting a NullREference Exception at StartCoroutine(Wait(3.0f))… any ideas
First of all, I don’t think this does what you think it does.
It’s just going to start 4 separate coroutines at the same time that wait for 3 seconds in parallel. It’s not going to temporally space out those lines between them.
Secondly, can you post the whole error log and not just “NullReferenceException”? It doesn’t make sense that StartCoroutine(Wait(3.0f)); would throw that exception. There aren’t any references on that line to be null.
hmmm i see what you are saying Pharan. I just want it where the player gets it then flickers on and off for a sec or two telling the user he was hit…
here is the full error
I have tried setting the game object as a public and assigning it to in the inspector instead of using GameObject.Find but that still trows me the error.
Still is throwing the same null error
I am using Artakas code above which is as fallows
IEnumerator Flicker(Renderer theRenderer, float waitTime, int flickerCount)
{
for (int i = 0; i < flickerCount; i ++)
{
theRenderer.enabled = false;
yield return new WaitForSeconds (waitTime);
theRenderer.enabled = true;
yield return new WaitForSeconds (waitTime);
}
}
private void Pdamaged (){
Renderer theRenderer = GameObject.Find ("Graphics").GetComponent<Renderer>();
StartCoroutine(Flicker(theRenderer, 3.0f, 2));
}
There needs to be both a GameObject called “Graphics” in your scene and also a Renderer component on that gameobject. You are missing either 1 or both of those things. Post your full script, post a screencapture of your scene setup.
I think I have both. Here is a screen shot and full line of code. The graphics are only place holders and are not mine. The code is not that clean because I am not a big coder as you can tell.
Since the "X"s are working we won’t touch those. For “Phit”, make sure that it’s assigned the “Graphics” gameObject by dragging “Graphics” onto the Phit slot in the inspector. Doing so will ensure that you have that variable assigned and you don’t have to use GameObject.Find to assign it. After doing so, remove line 46 and change line 26 to:
I have also change Phit instead of saying graphics i changed it to the soccer ball to see if that worked and still same issue when the player went into the collision box
Let’s try one more thing. Let’s eliminate Phil variable and manually assign the Renderer in the Inspector and see if you’re still getting a null error. Basically add a new public field “theRenderer” and drag the “Graphics” gameObject onto it in the Inspector and remove “Renderer theRenderer = Phit.GetComponent();” from Pdamaged. Here is what it should look like:
Same issue… If you look at my code i had something call AddPX () which then called Pdamaged()… I even took out where it went through AddPX(). Now my object just calls Pdamaged() and that is it. Same stupid issue…i have no idea how it could possibly be null.