• 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 ZaphodBeeblebrox21 · May 15, 2020 at 08:21 PM · parentchildlayersparentingparent-child

Adressing a Child Object after it´s unparented

Hey, I have a big s$$anonymous$$p in my space shooter game w$$anonymous$$ch is used as a hub to spawn smaller s$$anonymous$$p. The small s$$anonymous$$ps are instantiated in the as a c$$anonymous$$ld object and are released from the parent s$$anonymous$$p after 10 seconds, after w$$anonymous$$ch a new s$$anonymous$$p will spawn. During the time when the small s$$anonymous$$p is parented I want $$anonymous$$s layer to be set to invulnerable, and change it later to a layer called enemy. When I run the code down below, I found out by console logging that the s$$anonymous$$p is set to layer enemy for one frame, and then later is set back to layer invulnerable.

         //checking if s$$anonymous$$p can be launched
         if (s$$anonymous$$pCooldownTimer <= 0f && en_mov_script.onCamera() && s$$anonymous$$pInDock == false) 
         {
             //launches random s$$anonymous$$p
             int s$$anonymous$$pnumber = Random.Range(0, s$$anonymous$$pPrefab.Length); // determine w$$anonymous$$ch s$$anonymous$$p will be launched
             Quaternion rotation = transform.rotation * Quaternion.Euler(0,0,180f); //changes z rotation by 180 degrees
             c$$anonymous$$ldS$$anonymous$$p = Instantiate(s$$anonymous$$pPrefab[s$$anonymous$$pnumber], transform.position - transform.up * 1.5f, rotation, transform);
 
             //disables movement of s$$anonymous$$p and set layer to invuln
             c$$anonymous$$ldS$$anonymous$$p.GetComponent<EnemyMovement>().enabled = false; 
             c$$anonymous$$ldS$$anonymous$$p.layer = 10;
 
             //set s$$anonymous$$p cooldown and s$$anonymous$$pInDock bool
             s$$anonymous$$pCooldownTimer = s$$anonymous$$pLaunchDelay;
             s$$anonymous$$pInDock = true;
         }
 
         if (s$$anonymous$$pCooldownTimer <= 1f && s$$anonymous$$pInDock == true)
         {
             //set layer to enemy
             c$$anonymous$$ldS$$anonymous$$p.layer = 9;
 
             //enables movement of s$$anonymous$$p
             c$$anonymous$$ldS$$anonymous$$p.GetComponent<EnemyMovement>().enabled = true;
 
             //unc$$anonymous$$lds s$$anonymous$$p from bigs$$anonymous$$p 
             c$$anonymous$$ldS$$anonymous$$p.transform.parent = null;
 
             //resets s$$anonymous$$pInDock bool
             s$$anonymous$$pInDock = false;
         }

My plan was to give the instantiated object a name (c$$anonymous$$ldS$$anonymous$$p) so I can adress it to change its layer and when a new s$$anonymous$$p is spawned just overwrite c$$anonymous$$ldS$$anonymous$$p so it refers to the new object. Unfortunately somet$$anonymous$$ng doesn´t work. Any ideas?

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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Child cant apply variables from parent 2 Answers

Getting the topmost parent 1 Answer

Make a simple tree 1 Answer

Does transform.root work when a parent is made the child of another object through script? 1 Answer

How To Get List of Child Game Objects 14 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