- Home /
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![alt text][1]
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
[1]: /storage/temp/139493-home4.png
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.
thanks for reply, cube script on my player and how to access a rigidbody.velocity of player in game manager??
public class Game$$anonymous$$anager : $$anonymous$$onoBehaviour
{
Rigidbody rigidbody;
void Start()
{
rigidbody = GameObject.Find("NameOfPlayerObject").GetComponent<Rigidbody>();
}
}
Why would player be stopped? From what you have priovided, Player$$anonymous$$anager.moving
has nothing to do with actuall player(cube) movement...
@Doctor_ED thakns for replay cube script put on player when my player collect all point then i want to stop my player but my player should be not stop??
Ok, then. From comment above I can see that you are not using Rigidbody, but can you please provide a script, where you are actually moving that cube. I can't see what I can't see...
Answer by niorg2606 · Jun 06, 2019 at 01:30 AM
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.
@niorg2606 The hit variable is likely from a raycast that is not happening in FixedUpdate(). OnTrigger/OnCollision methods do not have a RaycastHit
@highpockets That is true. I'd say use OnTriggerEnter along with other.gameObject.tag