Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by rahulpatil6220375 · Jun 05, 2019 at 05:41 AM · playerboolstop

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 alt text

[1]: /storage/temp/139493-home4.png

home4.png (10.5 kB)
player-4-rigid-body.png (62.1 kB)
Comment
Add comment · Show 17
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image highpockets · Jun 05, 2019 at 08:14 AM 0
Share

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.

avatar image rahulpatil6220375 highpockets · Jun 05, 2019 at 08:46 AM 0
Share

thanks for reply, cube script on my player and how to access a rigidbody.velocity of player in game manager??

avatar image highpockets rahulpatil6220375 · Jun 05, 2019 at 08:58 AM 0
Share
 public class Game$$anonymous$$anager : $$anonymous$$onoBehaviour
 {
 
 Rigidbody rigidbody;
 
 void Start()
 {
 rigidbody = GameObject.Find("NameOfPlayerObject").GetComponent<Rigidbody>();
 }
 }

Show more comments
avatar image Doctor_ED · Jun 05, 2019 at 08:38 AM 0
Share

Why would player be stopped? From what you have priovided, Player$$anonymous$$anager.moving has nothing to do with actuall player(cube) movement...

avatar image rahulpatil6220375 Doctor_ED · Jun 05, 2019 at 08:44 AM 0
Share

@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??

avatar image Doctor_ED rahulpatil6220375 · Jun 05, 2019 at 09:22 AM 0
Share

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...

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image highpockets · Jun 06, 2019 at 05:41 AM 0
Share

@niorg2606 The hit variable is likely from a raycast that is not happening in FixedUpdate(). OnTrigger/OnCollision methods do not have a RaycastHit

avatar image niorg2606 · Jun 06, 2019 at 11:37 AM 0
Share

@highpockets That is true. I'd say use OnTriggerEnter along with other.gameObject.tag

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

129 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Stop object from moving 1 Answer

Edit this script so that the player stops at a distance and attack? 0 Answers

Stop player cube from going trough the walls 2 Answers

c# code. static bool. 1 Answer

How to stop the enemy from jumping when chasing the player ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges