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 /
avatar image
0
Question by noobunity · Sep 28, 2014 at 06:16 AM · prefabprefabs

Display GUI menu after last object left the screen

Hi guys

I am creating one game where my camera is still and some objects pass from front of the camera from right to left.

I am trying to display the GUI menu after last object left the screen. But don't know how to do that.

This is my game master script where I am instantiating prefabs

 #pragma strict
 
 
 var respawn1:GameObject;
 var randomcars:int;
 var i:int;
 
 function Start () {
 
 randomcars = Random.Range(10,20);
 
 for (var i : int = 10;i < randomcars; i++) {
         Instantiate (respawn1, Vector3(i * 5, 0, 0), Quaternion.identity);
     }
 
 }
 
 function Update (){
 }

2nd is my obejct script , just to move object from right to left of screen

 #pragma strict
 
 var moveSpeed= -5;
 
 function Start () {
 
 
 }
 
 function Update () {
 
 transform.position.x += moveSpeed * Time.deltaTime; 
 
 if (transform.position.x <-12){
 Destroy(gameObject);
 }
 }
 
 



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

1 Reply

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

Answer by robertbu · Sep 28, 2014 at 06:20 AM

I see you are destroying your objects when they are off the screen. If you tag your game objects with the same, unique tag, you can integrate the following into your code:

 var showGUI = false;
 
 function Update() {
      showGUI = (GameObject.FindWithTag("TagOnObjects") == null);
 }
 
 function OnGUI() {
     if (showGUI) {
         // GUI code goes here
     }
 }

Comment
Add comment · Show 5 · 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 noobunity · Sep 28, 2014 at 06:05 PM 0
Share

Hi Robertbu, sorry but I didn't get it. I am noob. So here is the thing. I have one obejct, its a prefab and it has tag "cars". So I am instantiating that prefab from right of the screen (in random numbers). So lets say 4 prefabs generated and they all have "Player" tag. And now when all 4 prefabs go out of screen (to left) I am trying to pop up GUI. So where should the above code will go? it can't go to that prefab object right? because its getting destroyed. So do you mean this will go to the game master script?

And I couldn't understand the logic

showGUI = (GameObject.FindWithTag("TagOnObjects") == null);

If you please explain me, that would be great

Thanks

avatar image Kiwasi · Sep 28, 2014 at 06:45 PM 0
Share

Put it on a master script.

GameObject.FindWithTag returns null if no objects are found. So if this is == null then you set showGUI to true. And your GUI shows up.

avatar image Kiwasi · Sep 28, 2014 at 06:48 PM 0
Share

One more advanced way to do this is to have your spawn script run as a coroutine. Once all of the spawning is complete you then start checking if any objects remain on screen. This approach allows you to have lulls in your spawn script without problems.

avatar image robertbu · Sep 28, 2014 at 08:56 PM 0
Share

As usual, both @Bored$$anonymous$$ormon's comments are correct. Put the script on any game object that is not getting destroyed. And reiterating, this line:

  showGUI = (GameObject.FindWithTag("cars") == null);

sets 'showGUI' to true when no object are found with the given tag.

avatar image noobunity · Sep 29, 2014 at 01:24 AM 0
Share

Thank you very much Robertbu & Bored$$anonymous$$ormon. It is working now.

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

2 People are following this question.

avatar image avatar image

Related Questions

Script is reading from prefab instead of instance 1 Answer

Prefab mode doesn't show prefab, still shows old scene. 7 Answers

Scale and save prefab 0 Answers

Prefub Edit Collider buttons are not displayed on the Scene 0 Answers

Logic problem with RaycastHit and prefabs scripts 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