How to stop first person controller (from standard asssets) move when game over condition?

I have a question about first person controller, which i have from standard assets. How can i stop moving this controller after game over condition in my game?
That is after my health points are 0 i want to stay in one place and cant walk, jump, etc, and next i will set my game-over screen. I think that i must set something in script and function death() but how to do that with fpc controller?

Thanks for help!

to keep it very very simple, disable the Component after Death

But when i set the object: public static FirstPersonController fpc; and then make: fpc.enabled=false; in my death function i get: NullReferenceException: Object reference not set to an instance of an object.
Is there any other option to solve this problem or maybe i turn it off wrong?

Then check it before you use it, if you are obviously expecting it to be Destroyed (which you are expecting)!!

In any case, regardless of your final engineering choices above, the answer is always the same… ALWAYS. It is the single most common error ever. Don’t waste your life on this problem. Instead, learn how to fix it fast… it’s EASY!!

Some notes on how to fix a NullReferenceException error in Unity3D

  • also known as: Unassigned Reference Exception
  • also known as: Missing Reference Exception

http://plbm.com/?p=221

The basic steps outlined above are:

  • Identify what is null
  • Identify why it is null
  • Fix that.

Expect to see this error a LOT. It’s easily the most common thing to do when working. Learn how to fix it rapidly. It’s easy. See the above link for more tips.

This is the kind of mindset and thinking process you need to bring to this problem:

https://discussions.unity.com/t/814091/4

Step by step, break it down, find the problem.

You can put the input checks in an if condition, so the character will only move if the game is not over. You’d want to do the same thing with the mouse look.

if (!gameOver) {
if (Input.GetKeyDown()) // etc

Or you can set the move, rotate, and jump parameters to 0 :wink:

Timescale to 0 will pause all movement :slight_smile:

1 Like

Agreed, that’s the easiest. The only issue is if you still want other objects moving visually (“the world moves on”) even when the character is dead, it’s just a design decision.

Yeah in our game we disabled interaction and movement and grayed the screen for 5 seconds before returning player to load out / spawn select. If your controller is well designed it shouldn’t be a hard task

1 Like