Still Try to access ... Script Error .

Here i post my topic in right forum - MissingReferenceException: Please help - Unity Engine - Unity Discussions

The error tells you exactly what’s wrong and where. Look at line 17 in your CameraController.cs. It’s trying to do something with one of the game objects that you’ve destroyed.

1 Like

Thanks for the fastest reply .
so how can i correct it , can you please suggest me (i am a newbie)

And one more thing that how can i print my health using debug.log

go to line 17. Add this around it and replace “someObject” with whatever object you’re trying to access Again, look at the error:

if(someObject != null)
{

}
1 Like

Can you please tell me because it’s too much hard for me (i am a newbie in c#)
to understand where i have to write and what to write instead of “some object”
Is it add with tag like gameobject.tag==“Player” != null or something like that .
Please reply me and help me fast .

I highly recommend you start with the beginner tutorials and documentation, otherwise we’ll be doing this all day:

2 Likes

That’s right .
thanks .

So is there the memory leaks .
So here i can i stop this , thanks

If i add this one in my CameraController.cs in LateUpdate() Function

  • if (gameObject != null)
  • {
  • // Do something
  • Destroy(gameObject);
  • }

then Console said “There are no audio listeners in the scene. Please ensure there is always one audio listener in the scene”
and my camera didn’t show anything
and if i add in enemy nothing happens it will continuously saying about my first error if the player destroy .
Please help me .

The console says you need at least one AudioListener in the scene. This is a component which you can attach to any object. Generally the main camera has automatically attached one, so if you destroy the camera, it’s gone, thereby causing the error.

yes that’s what actually happens can you please tell me how can i insert this to get rid from this two “Missing Reference Errors”

The problem in your other script is, that on the collision with the enemy you destroy the player (including its camera), instead of destroying the enemy. This part causes all errors:

When you use “gameObject” the GameObject where the script is attached to is referred.
So in your case you actually destroyed the Player himself. Instead you want to delete the colliding GameObject which is: Destroy(col.gameObject);

When i destroy the collision of the “Player” Game Object same thing will happen (Two errors )
I just assign health for enemy but here in the enemy script i destroy the collision of player but again those errors .