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 Dogg · Aug 23, 2014 at 03:11 AM · destroydisableenableactive

How To Keep GameObjects From Enabling Again?

Sorry for the second question of today, please excuse me. As you read in the title, how can I keep GameObjects From Enabling Again after they have already been destroyed? In my game, I fade into the scene but with the same scene, not from a different scene. It plays a little animation and then fades. Before it fades the objects get destroyed. What I want to do, is after it get's destroyed, to never spawn it again unless the Player restarts the game or something, because if I clicked a button and went to a different scene and then clicked back, it would play the little animation and have to destroy the objects again. So how can I keep certain gameobjects from reactivating and from coming back after being destroyed or disabled?

By the way, I use GameObject.active to get rid of the gameobjects I want in this scene.

Comment
Add comment · Show 5
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 b1gry4n · Aug 23, 2014 at 03:16 AM 0
Share

if you keep loading in to the same scene it will keep giving you the same objects in that scene. if you need the objects only once and have some sort of game manager, instantiate them, destroy them, never instantiate again until the next playthrough

That or have 2 scenes that are the same except one has the objects already deleted. Just save your current scene as "$$anonymous$$ySceneB" or something and remove the things you dont want. load into that scene

avatar image Dogg · Aug 23, 2014 at 03:20 AM 0
Share

I don't have some sort of game manager. All I have is this script:

 #pragma warning disable 0618
 
 using UnityEngine;
 using System.Collections;
 
 public class ActivateScript : $$anonymous$$onoBehaviour {
 
     public GameObject BScreen;
     public GameObject ScreenFader;
     public GameObject Light;
     public $$anonymous$$ain$$anonymous$$enu HOLDER;
     public GameObject Name;
 
     void Start()
     {
         HOLDER = GetComponent<$$anonymous$$ain$$anonymous$$enu> ();
         StartCoroutine (ScriptEnable ());
         BScreen.active = true;
         ScreenFader.active = false;
         Light.active = true;
         StartCoroutine (ScreenDisable ());
         StartCoroutine (NameEnable ());
     }
 
     IEnumerator ScreenDisable()
     {
         yield return new WaitForSeconds (7.0f);
         BScreen.active = false;
         Light.active = false;
         ScreenFader.active = true;
     }
 
     IEnumerator NameEnable()
     {
         yield return new WaitForSeconds (4.9f);
         Name.active = true;
     }
 
     IEnumerator ScriptEnable()
     {
         yield return new WaitForSeconds (14.0f);
         HOLDER.enabled = true;
     }
 }
 

Isn't there some code to "never instantiate again until the next playthrough?"

avatar image b1gry4n · Aug 23, 2014 at 03:22 AM 1
Share

the easiest solution imo is to just save your current scene as another name, delete the objects you only want once in your first scene, and load into the second. they are essentially the same scene just without those objects

by delete i mean manually remove them from the second scene

avatar image Dogg · Aug 23, 2014 at 03:22 AM 0
Share

I just read your edit, not a bad idea. I'll see if that works. Thanks.

avatar image Dogg · Aug 23, 2014 at 03:36 AM 0
Share

I just tried it, thank you it appears to work very well. You should post it as an answer so that I can accept it. Thanks again.

2 Replies

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

Answer by Dogg · Sep 14, 2014 at 11:17 PM

The answer is making a copy of the scene I want, and getting rid of the game objects that I don't need. Then you load the scene when you need it. This answer was from b1gry4n, so thank him/her.

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 rafaelbarretobra · Jan 17, 2017 at 08:15 AM

I have a better solution. When the player gets an item in my game, I use it's position Vector3 as a unique float for that item, for example: the player gets an iron sword (after that, I want that sword gone for good).

So, in the Iron Sword script, I do:

bool isDestroyed = false;

float uniqueID = this.transform.position.x+this.transform.position.y+this.transform.position.z;

void Start(){

if (PlayerPrefs.GetFloat(uniqueID) == 1) Destroy(this);

}

void GetSword(){ PlayerPrefs.SetFloat(uniqueID, 1); }

I know it's not so elegant, but I'm not an elegant programmer :D

Contact me if you need more help.

MP Game Studios mundiproject@hotmail.com

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

24 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

Related Questions

[Solved]cant disable/enable scripts 1 Answer

Disable & Re-enable Script 1 Answer

Enable/Disable shader on script 2 Answers

If you disable a gameobject, does an InvokeRepeating loop end or pause? 3 Answers

Why does Unity disable the Collider when I Destroy the Rigidbody? (2D) 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