title: How to enable / disable player movement in unity?
body: <p>So, I'm making a game where one player changes control of two characters with the press of shift, so, when shift is pressed, the player 1 movement is disabled and the player 2 script is enabled, I approached this by making the movement speed and jump reach numbers as zero, but when shift is pressed, nothing happens, what can I do to counter this?</p>
  
  <p>By the way, I set the Fire2 for "shift" to clarify, and also focus on the "CanPlay" variable, because it's where I think the problem is.</p>
  
  <p>Code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class movimento : MonoBehaviour
  {
  
      public bool CanPlay;
  
      void Update()
      {
          float h = Input.GetAxisRaw("Horizontal");
          float speedY = PlayerRB.velocity.y;
  
          PlayerRB.velocity = new Vector2(h * speed, speedY);
  
          if (Input.GetButtonDown("Jump") &amp;&amp; Isgrounded == true)
          {
              PlayerRB.AddForce(new Vector2(0, jumpforce));
          }
  
          if (h &gt; 0 &amp;&amp; IsLookLeft == true)
          {
              Flip();
          }
          else if (h &lt; 0 &amp;&amp; IsLookLeft == false)
          {
              Flip();
          }
  
          if (CanPlay = false)
          {
              speed = 0f;
              jumpforce = 0f;
          } 
  
          if (CanPlay = true)
          {
              speed = 10f;
              jumpforce = 150f;
          }
  
          if (Input.GetKeyDown("Fire2"))
          {
              CanPlay = !CanPlay;
          }
      }
  }
  
  
  </code></pre>