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 /
  • Help Room /
avatar image
0
Question by JunekCZ · Apr 14, 2016 at 12:10 PM · collisionmovement scriptbool

Bool paused in collision

Good day.

I making the movement script with bool paused. (if(col.gameObject.tag == "Bullet(Clone)") paused true... but it doesn't work.

Here is the code:

 public class Tank2 : MonoBehaviour {
 
     public GameObject Bullet;
     public float moveSpeed = 10f;
     public float turnSpeed = 120f;
     public Text Vyhra;
     public GameObject protivnik;
     public GameObject teleport;
     public Text ScoreA;
     public int TankA;
     public bool paused;
     void Start () {
         gameObject.GetComponent<Renderer>().material.color = Color.green;
         TankA = 0;
         SetTextA ();
     }
     void OnPausedGame (){
         paused = true;
     }
     void OnExitGame (){
         paused = false;
     }
 
     // Update is called once per frame
     void Update () {
         if (!paused) {
             if (Input.GetKey (KeyCode.W)) {
                 transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime);
             }
             if (Input.GetKey (KeyCode.S)) {
                 transform.Translate (-Vector3.forward * moveSpeed * Time.deltaTime);
             }
             if (Input.GetKey (KeyCode.A)) {
                 transform.Rotate (-Vector3.up * turnSpeed * Time.deltaTime);
             }
             if (Input.GetKey (KeyCode.D)) {
                 transform.Rotate (Vector3.up * turnSpeed * Time.deltaTime);
             }
         }
     }
 void OnCollisionStay(Collision col) {
     if(col.gameObject.name == "Kulka(Clone)") {
         Destroy (col.gameObject);
         TankA = TankA + 1;
         SetTextA();
         StartCoroutine (dcoLoadLevel ("tanky", 5.0f));
     }
 }
 IEnumerator dcoLoadLevel(string tanky, float delay) {
     yield return new WaitForSeconds (delay);
     teleport.transform.position = new Vector3(13, 8f, 21);
     this.transform.position = new Vector3(18, 8f, 21);
 }
 void SetTextA(){
     ScoreA.text = "Score: " + TankA.ToString ();
     if (TankA >= 10) {
         Vyhra.text = "Vyhral cerveny hrac!";
         StartCoroutine (coLoadLevel ("menu", 5.0f));
     }
 }
 IEnumerator coLoadLevel(string Menu, float delay) {
     yield return new WaitForSeconds (delay);
     Application.LoadLevel (Menu);
 }
 }

Thank you for help

Comment
Add comment · Show 2
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 Rickywild · Apr 14, 2016 at 02:02 PM 0
Share

I don't see the paused bool being set to true anywhere. You might want to set it to false in Start() too. I'm assu$$anonymous$$g when you set the boolean to true, you have coded else where something along the lines of,

 Time.timeScale = 0f;

I think this will only work if you're working with Time.deltaTime;

Hope that helps, if not will need more detail.

avatar image JunekCZ Rickywild · Apr 18, 2016 at 11:28 AM 0
Share

I paste paused = true on start() but its still doesn't work.

Time.timeScale = 0f; Can't work here, because i have IE numerator and i think that will not countdown.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JunekCZ · Apr 20, 2016 at 02:19 PM

Okey i solve that!

I dont know that i must make that rigidbody.

But thank you for comment ;).

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Limit of a move for position 1 Answer

hi guys am having a problem with my player 0 Answers

Shopping Cart Movement 0 Answers

How to check if an object has collided from another script? 1 Answer

Transform.Translate snaps back in FixedUpdate 0 Answers


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