how to stop the player when gameover??

problem is when game over myplayer not stop??cube(player) not stop??

Code:

1.playermanager.cs

public class PlayerManager : MonoBehaviour
{
     internal static bool moving;
}

cube.cs

 private void FixedUpdate()
 {
    if (hit.collider.gameObject.tag == "Obstacle")                                        
     {
                    PlayerManager.moving = false;
    }
}

GameManager.cs

Rigidbody rb;
int managehome;
bool stops;

void FixedUpdate()
{
    completecall();
}
void Start()
{
    rb = GameObject.Find("Player4").GetComponent<Rigidbody>();
}

void completecall()
{   
     switch (managehome)
        {
            case 1:
                home2.SetActive(true);                                      //home2 active
                Debug.Log("run or not");
                home1.SetActive(false);
                home3.SetActive(false);
                home4.SetActive(false);
                StartCoroutine(playeractivesecond());        //second player active![139493-home4.png|235x259](upload://bg1pKfBNsCmFJBOpjcMiBPCbZY0.png)
                managehome++;
                homeanim2.enabled = true;                                
              
                break;

            case 2:
                home3.SetActive(true);                                       //home3 active
                home2.SetActive(false);
                home1.SetActive(false);
                home4.SetActive(false);
                StartCoroutine(playeractivethird());           //third player active
                managehome++;
                homeanim3.enabled = true;
                                   break;

            case 3:

                home4.SetActive(true);                                       //home4 active
                home1.SetActive(false);
                home2.SetActive(false);
                home3.SetActive(false);
                StartCoroutine(playeractivefour());      //fourth player active
                homeanim4.enabled = true;
                
                managehome++;
               
                break;

            case 4:
                gameovercanvas.SetActive(true);
                rb.velocity = Vector3.zero;  // i want to home 4 player stop when gameover canvas call  //but still he move                   

}

Home4:Player4:

RigidBody CubeScript:

player4 rigidbody

This really depends on how you are moving your player. But if you are using a rigidbody for example:

rigidbody.velocity = Vector3.zero;

will zero out the rigidbody velocity.


You haven’t given enough info to help you here. You should explain how you move the character.

You put your collision detection code in FixedUpdate instead of OnTriggerEnter/OnCollisionEnter in cube.cs

Also, you should not use the internal keyword for your variable. Use the attribute [HideInInspector] instead.