0
\$\begingroup\$

problem is when game over myplayer not stop??

cube.cs  //script on my player(cube)

 public void MovementOfPlayer()
     {
         if (PlayerManager.moving)
         {
             transform.Translate(Vector3.forward * Time.deltaTime * speed);     //cube move
         }   
     }


GameManager.cs //create empty game object and add this script

 Rigidbody rb;

 bool stops;

 void Start()
 {
     rb = GameObject.Find("Player4").GetComponent<Rigidbody>();
 }
void completecall()
 {   
      switch (managehome)
         {
             case 1:
                 //some code here   //activate 1 home
                 break;
             case 2:
                 //some code here  //activate 2 home
                 break;
             case 3:
                  //some code here  //activate 3 home
                 break;
             case 4: 
                 gameovercanvas.SetActive(true);  //when 4 home complete then gameoverpanel on
                 rb.velocity = Vector3.zero;  // i want to home 4 player stop when gameover canvas call  //but still he move
              break;
}



when game over myplay will be move but i want to stop my player.what i m trying to do now rb.velocity=Vector3.zero;

Referance: enter image description here

\$\endgroup\$
0
\$\begingroup\$

You could use time.timeScale = 0 And, you should use GameObject.FindObjectWithTag() it is more efficient than GameObject.Find() if you would not like the more efficient drag and drop.

\$\endgroup\$
  • \$\begingroup\$ i m not using rigidbody in my program.and add this line in my program Time.timeScale = 0; and myplayer should be stop.thanks given suggestion \$\endgroup\$ – rahul patil Jun 6 at 5:45
0
\$\begingroup\$

You could simply Destroy the player game object when the player loses. This also destroys any controllers on it. Just make sure that all other behaviours in the scene which reference the player can deal with this situation.

If you still want some visual indicator which shows where the player died (like a dead sprite or an explosion particle effect) you can instantiate this as a new game object in its place.

\$\endgroup\$
  • \$\begingroup\$ before i m trying boolean variable ` if (PlayerManager.moving==false) { PlayerManager.locked = true; } ` my player should be stop in pc but in mobile player should be not stop can u suggest why my player should be stop in pc but not in mobile???? \$\endgroup\$ – rahul patil Jun 7 at 10:36
  • \$\begingroup\$ @rahulpatil This appears to be a new question which is not related to this answer. Please ask it as a new question. Remember to provide all the sourcecode of the class PlayerManager which is relevant to this problem. \$\endgroup\$ – Philipp Jun 7 at 10:43
0
\$\begingroup\$

I am not sure i understand you very well but i would implement a property in the input controller to enable/disable input and on movement check if it is enabled or not before applying the actual movement.

\$\endgroup\$
  • \$\begingroup\$ when game end add this line Time.timeScale = 0; and when game start Time.timeScale = 1; i m trying rigidbody but not solve my problem \$\endgroup\$ – rahul patil Jun 7 at 9:54
  • \$\begingroup\$ Usually Time.timeScale = 0; should do the trick.. Are you moving your rigidbodys transform (like Translate) or do you apply it directly to your rigidbody (like AddForce)? \$\endgroup\$ – MBrain Jun 10 at 20:07
  • \$\begingroup\$ i m using ` if (PlayerManager.moving) { transform.Translate(Vector3.forward * Time.deltaTime * speed);` \$\endgroup\$ – rahul patil Jun 11 at 9:18
  • \$\begingroup\$ When your PlayerManager includes everything you want to stop then you can simply deactivate or destory it like other comments said. \$\endgroup\$ – MBrain Jun 13 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.