Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Disable Movement

Discussion in 'Scripting' started by ChristerMN, Jul 7, 2014.

  1. ChristerMN

    ChristerMN

    Joined:
    Dec 1, 2012
    Posts:
    8
    Hey

    I'm trying to disable the players ability to move my games character in C#. Right now I have the character playing its death animation when it makes contact with a trigger collider, but the player can still move the character lying face up on the ground, right left up down.

    I've been reading several posts on this but none have either an answer or get a very specific code for their needs.

    you would think it would be easy to just disable a specific key or ability from the input list but so far I haven't found it.

    Anyone know a good way?
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Assuming that you are fetching input from a single script's Update method, simply disable that component.
     
  3. Pysassin

    Pysassin

    Joined:
    Dec 27, 2012
    Posts:
    87
    If your using physics to move your character just make the rigidbody kinematic
     
  4. WizardCube

    WizardCube

    Joined:
    Dec 31, 2013
    Posts:
    77
    Either this or just have a boolean check for your main movement update.
     
  5. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Code (csharp):
    1.  
    2.  
    3. void Update()
    4. {
    5.   if(isDead)
    6.      return;
    7. }
    8.  
    9.  
     
    ChristerMN likes this.
  6. ChristerMN

    ChristerMN

    Joined:
    Dec 1, 2012
    Posts:
    8

    Thanks

    I added

    if (dead)
    {
    return;
    }

    to the code and that did the trick.

    Thanks again!