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 Cnote · Oct 24, 2014 at 06:59 AM · arrays

How To Disable, Not Deactivate All GameObjects In Array

Hi there,

Well, I have spent 4 hours tonight researching and reading Unity Answers to try and find a solution to a SIMPLE problem. Maybe my head is just too stuffed with information today.

I have an array of GameObjects which I access a script attached to each one of those gameobjects. These scripts have animations attached to them.

I want to be able to access the script on a button click, and on the same button click disable the gameobject. But, I want the script to continue playing after the button click, just do nothing upon a second button click. However the button has to remain active for all new objects added to the array.

 using UnityEngine;
 using System.Collections;
 
 public class GameController : MonoBehaviour {
 
     GameObject[] bombs;
     GameObject[] explosions;
     private InventoryControl inventoryControl;
 
     void Start () 
     {
         GameObject inventoryControllerObject = GameObject.FindGameObjectWithTag ("GameController");
         inventoryControl = inventoryControllerObject.GetComponent<InventoryControl> ();
     }
 
 
     void Update () 
     {
         if (Input.GetMouseButtonDown(0))
         {
             Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
             RaycastHit hit;
             if (Physics.Raycast (ray, out hit, 5)) {
                 Quaternion q = Quaternion.FromToRotation(transform.up, hit.normal);
                 Instantiate (inventoryControl.activeBomb, hit.point+hit.normal*0.01f, q);
             }
         }
     }
 
     public void explodeBomb()
     {
         bombs = GameObject.FindGameObjectsWithTag ("Bombs");
         explosions = GameObject.FindGameObjectsWithTag ("Explosions");
 
         for (int i=0; i<explosions.Length; i++) 
         {
             explosions [i].GetComponent<Detonator> ().Explode ();
             foreach (GameObject Explosions in explosions)
             {
                 //I know something goes here to do what I want!!!1
         }
         
         for(int i=0; i<bombs.Length; i++)
         {
             Destroy(bombs[i]);
         }
     }
 }
 

I'm losing my mind! It seems like this should be easy.

As always, you guys are awesome, and I know someone smarter than me will have a quick solution.

Thanks,

Cnote

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
1
Best Answer

Answer by Tanshaydar · Oct 24, 2014 at 08:16 AM

If I understand right, you don't want to see the gameobject, but want the script to continue executing.

If you deactivate a gameobject, all of its components will be disabled. You can, but, access each component individually and disable them one by one (unless they require each other, like joints require rigidbody).

If you want script to continue execute but don't want to see the object you can disable its mesh renderer. Furthermore, if the object has collider and you don't want it to affect the game anymore, you can access collider and disable it too.

Comment
Add comment · Show 4 · 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 Cnote · Oct 24, 2014 at 03:17 PM 0
Share

Hi, sort of. I want the gameobject to continue it's already activated script, but I don't want it to receive input, as in button clicks, etc.

avatar image Tanshaydar · Oct 24, 2014 at 04:24 PM 0
Share

Well, you can include something like

 public bool objectIsNotExlpoded;
 
 if( objectIsNotExlpoded){
      // all Update and FixedUpdate input checks here respectively
 }

then set objectIsNotExlpoded to false.

avatar image Cnote · Oct 27, 2014 at 04:51 AM 0
Share

Hey there Tanshaydar, the answer I was looking for was your comment to my comment to your question. I knew it was something simple I was missing! haha

avatar image Tanshaydar · Oct 27, 2014 at 08:08 AM 0
Share

Glad to be help :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to return index of List element? 1 Answer

How to store and iterate through a lot of Vector2s? 2 Answers

How many audio clip arrays are supported? 1 Answer

Get all GameObjects by variable value 2 Answers

Variable not accesible 2 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