Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Aug 31, 2017 at 08:01 AM by Jeric-Miana.
avatar image
0
Question by Jeric-Miana · Jul 21, 2014 at 03:55 AM · transformpositionpausing

hi everyone, i have a problem in my pause script, when i press the pause button my zombie is still moving . can anyone help me :(

alt text

///////////////////// Pause Script/////////////////////////

 #pragma strict
 //private var zombies;
 var count : int =2;
 function Start () {
     
 //zombies=GameObject.FindGameObjectsWithTag("zombie");
 }
 
 function Update () {
 if(count==2)
 {
 Time.timeScale=1;
 //zombies.GetComponent.<movement>().Go();
 }
 if(count==1)
 {
 Time.timeScale=0;
 //zombies.GetComponent.<movement>().Stop();
 }
 if(count==0)
 
 {
 
 Reset();
 }
 
 }
 function Reset()
 {
 count=2;
 
 }
 function OnMouseDown()
 {
     Debug.Log("Paused!");
     count-=1;
 
 }


zombiee.png (313.3 kB)
Comment
Add comment
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

2 Replies

  • Sort: 
avatar image
3

Answer by Kiwasi · Jul 21, 2014 at 04:01 AM

That's the wackiest way I've ever seen to write a pause script. Everything in the zombie script should rely on time. This means that the zombie will stop without any other interaction when timescale = 0

Here's a more efficient way to code it. You can delete everything else from the script.

 var isPaused : bool = false;
 
 function OnMouseDown()
 {
     isPaused = !isPaused;
     if(isPaused){
         Time.timeScale = 0;
     } else {
         Time.timeScale = 1;
     }
 }




Comment
Add comment · Show 3 · 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 Jeric-Miana · Jul 21, 2014 at 05:14 AM 0
Share

thanks for the script @Bored$$anonymous$$ormon! its more efficient :) hmm what do you mean my zombie should rely on time?
my zombie script have a transform.position -= Vector3(0,0.5,0); how can i stop it? :(

avatar image drex150 · Jul 21, 2014 at 07:34 AM 1
Share

What he means is that you should use Time.deltaTime for your zombie movement. Basically: transform.position -= Vector3(0,0.5 * Time.deltaTime,0);

Doing that will mean the zombie will no longer be able to move once you pause because timescale will equal 0, thus Time.deltaTime will equal 0 as well. Now he will have no movement ability in the y axis because it will be set to 0.

avatar image Kiwasi · Jul 21, 2014 at 08:56 PM 0
Share

@dres150 pretty much has is covered

@raymanbs answer is another way to achieve the effect.

avatar image
0

Answer by raymanbs · Jul 21, 2014 at 09:30 AM

you can try this in your zombie script:

 function Update () {
      if (!isPause){
          do();
     }
     else{
      //nothing
     }
 }
 function do()
 {
     //your code
 }
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 Kiwasi · Jul 21, 2014 at 08:57 PM 0
Share

You can also check if Time.timeScale == 0 ins$$anonymous$$d.

avatar image Jeric-Miana · Jul 22, 2014 at 05:45 AM 0
Share

thanks @Bored$$anonymous$$ormon, @drex150, @raymanbs! :D i want to vote up with your answers but I don't have enough repu XD thumbs up!

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

transform.position.y and x or z + 1? 0 Answers

Problem with transform 2 Answers

Vector3.Lerp doesn't work! 1 Answer

Moving object with transform.position ignore other objects even if they collided 1 Answer

Need enemy to follow only active character 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