My Error Message I get at any frame (cause its in LateUpdate):
"*MissingComponentException: There is no 'Renderer' attached to the "Main Camera" game object, but a script is trying to access it.
You probably need to add a Renderer to the game object "Main Camera". Or your script needs to check if the component is attached before using it.*"
I call this function in LateUpdate():
CharacterFade();
void CharacterFade() {
if (RPG_Animation.instance == null)
return;
if (distance < firstPersonThreshold)
RPG_Animation.instance.renderer.enabled = false;
else if (distance < characterFadeThreshold) {
RPG_Animation.instance.renderer.enabled = true;
float characterAlpha = 1 - (characterFadeThreshold - distance) / (characterFadeThreshold - firstPersonThreshold);
if (RPG_Animation.instance.renderer.material.color.a != characterAlpha)
RPG_Animation.instance.renderer.material.color = new Color(RPG_Animation.instance.renderer.material.color.r, RPG_Animation.instance.renderer.material.color.g, RPG_Animation.instance.renderer.material.color.b, characterAlpha);
}
else {
RPG_Animation.instance.renderer.enabled = true;
if (RPG_Animation.instance.renderer.material.color.a != 1)
RPG_Animation.instance.renderer.material.color = new Color(RPG_Animation.instance.renderer.material.color.r, RPG_Animation.instance.renderer.material.color.g, RPG_Animation.instance.renderer.material.color.b, 1);
}
}
What am I doing wrong and how do I fix it?
↧