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 Dismortus · Nov 02, 2013 at 09:54 PM · gameobjectloadstaticsingleton

Don't render GameObject on load if already hit by player?

I hope I can make proper sense of my issue. I'm on a small platformer project for practice. I have boxes the player can break. Once you break a box, the material is changed so it looks "used". I can't use static variables because there is more than one instance (multiple boxes with same script attached.). I have some bonus rounds the player can enter (new scene). When the player is done w/ bonus, he goes back to the original scene file using Application.LoadLevel(last level I was in). The boxes are back to normal, and I can break them again and get higher and higher score. I don't want this. I want the boxes to still be "used" when I go back to the level. I have no idea where to look but here, I can't even think of what I would google for this...Note: DontDestroyOnLoad doesn't work either, because it just doubles the objects. The new ones are loaded, the old ones are still there, so there ends up being two boxes in one's place.

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 Freaking-Pingo · Nov 02, 2013 at 10:07 PM 0
Share

Why don't you create a static manager for this ins$$anonymous$$d? Surely you can't apply static variables to the boxes because there will be multiple instances of it, but what about a Box$$anonymous$$anager? A static manager that maintains each state of the box?

1 Reply

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

Answer by clunk47 · Nov 02, 2013 at 11:04 PM

One way you could do this would be to write a script with a static generic list of names. Just name the boxes accordingly (box1, box2, box3, etc..) in your hierarchy. Once you hit the box, have a script in your box add the box name to the static list. Say you have a script named BoxNames.cs:

 //BoxNames.cs
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class BoxNames : MonoBehaviour 
 {
     public static List<string> names = new List<string>();
 }



Then say you have a script on your box with a variable named 'isEmpty', which is a boolean. Let 'isEmpty' determine what materials to use on the box, pretty much which "state" the box is in. When you hit the box, make isEmpty true, and add your box name to the list. Then when you reload the scene, check if your current box's name exists in the static list. If it does, make empty true on Start().

Box.cs

 using UnityEngine;
 using System.Collections;
         
 public class Box: MonoBehaviour 
 {
     bool isEmpty;
         
     void Start()
     {
         if(BoxNames.names.Contains(gameObject.name))
         isEmpty = true;
     }
  }
 
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

17 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

Related Questions

Why should I use a game object for non-physical things? 2 Answers

Static List< GameObject> in Singleton 1 Answer

Using a static class & pass in gameObject or just add same script to multiple objects 1 Answer

What do the "active" and "static" checkboxes do? 1 Answer

Attaching GameObject and ParticleSystem to C# script 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