Search Unity

FPS dead of player

Discussion in 'Scripting' started by VamppiV, Jul 25, 2014.

  1. VamppiV

    VamppiV

    Joined:
    May 27, 2014
    Posts:
    18
    I'm making simple fps game. I'm looking for any good ideas how to make my player dead. I invented, that:
    When health of my player >=0, player is dead. Then player fall (I have animation) and screen is fade.

    But now I have problem: how to disable fps controller? I was looking for that on forum but no option I found is working. My code is in C# and FPSController is in JavaScript. So I have huge problem how to disable Javascript from C# script.

    But!

    I found that's enough to disable two codes: mouselook and FootsSound (that's my script). Screen is fade, so other scripts don't collidate with my idea. I found how to do that and everythings fine, but when my player is dead - my Unity crashes.

    I don't know what to do with that. Anyone of you have any idea? Maybe my idea from beggining is wrong and someone can write me how to do that right?

    That's my really simple code:

    void Update(){
    if (health <= 0) {
    gameObject.GetComponent<FootsSoundController>().enabled=false;
    gameObject.GetComponent<MouseLook>().enabled=false;
    alive = false;
    gameController.LoseGame ();
    }
    }

    (sorry for my english, I know I have problems with grammar)
     
  2. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Code (CSharp):
    1. gameObject.GetComponent<Just_Put_The_Name_Of_The_FPS_Controller_Here>().enabled=false;
     
  3. VamppiV

    VamppiV

    Joined:
    May 27, 2014
    Posts:
    18
    Yeah, I know, I found that - but it's doesn't work.

    Look at the picture, please. And when I'm doing e.g.:
    if (health <= 0) {
    gameObject.GetComponent<FootsSoundController>().enabled=false;
    gameObject.GetComponent<MouseLook>().enabled=false;
    gameObject.GetComponent<CharacterMotor>().enabled=false;
    alive = false;
    gameController.LoseGame ();
    }

    <characterMotor> is red and give communicate: the name CharacterMotor does not exist in the current context.
    And when I start game and my health<=0, Unity is cracked and I have to reset my computer.
     

    Attached Files:

  4. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    OK you need to disable the mouse look and fps input controller, that should prevent movement of the camera and player character.