• 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 paulonl · Apr 12, 2014 at 12:02 PM · javascriptguiheight

Win Script if y=100

I want to make a script so if I am at 100y the player gets You won and the game stops but if i reach y=100 the game stops but there's no GUI. this is my script

 #pragma strict
 
 var pause : boolean = false;
 var pauseGUI : GUITexture;
 pauseGUI.enabled = false;
 var Player : GameObject;
 
 function Start () 
 {
     if(Player.transform.position.y >=100)
         Time.deltaTime = 0;

     if(pause==true)
         pause = false;
     else
         pause = true;

     if(pause == true)
         pauseGUI.enabled = true;
     else
         pauseGUI.enabled = false;
 }

I am dutch so sorry if i made some spelling mistakes.

This is my new script

 #pragma strict
 
 var pause : boolean = false;
 var pauseGUI : GUITexture;
 pauseGUI.enabled = false;
 var Player : GameObject;
 
 function Update () {
 if(Player.transform.position.y >=100)
 Time.timeScale = 0;
 pauseGUI.enabled = true;
 if(pause==true){
 pause = false;
 }
 else {
 pause = true;
 } 
 if(pause == true) {
 pauseGUI.enabled = true;
 }
 else {
 pauseGUI.enabled = false;
 
 }
 }
Comment
Add comment · Show 1
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 Lachee1 · Apr 13, 2014 at 07:30 AM 0
Share

What you have there is a start to the script, but I am not entirely sure what the question is. You are making more of a statement than a question.

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Berenger · Apr 13, 2014 at 08:38 AM

The function start is only called once when the game starts running. You need to use the function Update instead.

You'll have to change the content of the function as well. You can't change the deltaTime, because it's just the time since the last frame. I'm assuming you want to freeze time, which is Time.timeScale. I don't know what you want to do with your pause variables though.

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
avatar image
0

Answer by Temo2Ginal · Apr 13, 2014 at 09:32 AM

Similar question with answer There.

Try putting everything from function start to function Update or fixedupdate I guess. Use Time.timeScale = 0.0 instead of Time.Deltatime

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
avatar image
0

Answer by akauper · Apr 13, 2014 at 06:36 PM

I want to make a script so if I am at 100y the player gets You won and the game stops but if i reach y=100 the game doesn't stops.

I think this needs explaining first. What is the difference between being "at 100y" and "reaching y=100".

As Berenger said you most likely need to be using update... But even so it's unclear what you are trying to accomplish in update

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

25 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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

GUI.Box NullReferenceException 0 Answers

How do I use a trigger to change the GUIText 2 Answers

I have doubt please help me 2 Answers

Changing the tint colour of materials 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