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 Halo500 · Sep 18, 2013 at 02:56 AM · parentnullparent-child

How to null children of main camera that is also a child?

 var start: Transform; // drag here the start empty object
 var end: Transform; // drag here the end empty object
 var duration: float = 1.6; // set duration of movement
 var isNotDead:boolean=true;
 var showGameOverScreenLboolean=false;
  
 function Update(){
   if(isNotDead){
     // other things that you don't want the player to do while dead here
     if(health<=0){
       isNotDead = false;
       KillPlayer();
     }
   }
 }
  
 function DeathCamera(){
   var cam: Transform = Camera.main.transform; // get camera transform
   cam.parent = null; // detach it from the player
   cam.position = start.position; // place the camera at the start position
   cam.LookAt(end.position); // make it look towards the end position
   var t: float = 0;
   while (t < 1){
     t += Time.deltaTime/duration;
     // move the camera towards the end position each frame
     cam.position = Vector3.Lerp(start.position, end.position, t);
     yield; // let Unity do other jobs til next frame
   }
   // movement ended - enable game over screen
   showGameOverScreen = true; // enable "Game Over" message in OnGUI
 }
  
 function KillPlayer(){
   DeathCamera(); // start DeathCamera coroutine
   // not sure if the line below effectively stops the player...
   GetComponent(CharacterController).enabled=false; //makes the player unable to move
   //Other things here - showGameOverScreen is activated by DeathCamera
   Screen.showCursor=true;
   Screen.lockCursor=false;
 }
  
 function OnGUI(){
   if(showGameOverScreen){
     //GUI code with whatever you want to have at the death screen.
   }
 }

So I have recently gotten this awesome script. The issue I'm having is that once the camera move towards my Monster's face from death, children of the Main Camera also follow the camera. I have spotlights with a flashlight under the Main Camera, and I'm trying to null the children of the camera, which is also a child of the First Person Control Player. Of course seeing your flashlight randomly flying towards the Monster as you died looks ridiculous. Any help would be great! :)

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 DaveA · Sep 18, 2013 at 03:03 AM

What do you mean by 'null the parent'? Setting the transform.parent to null makes it a top-level object. Are you saying you want to 'detach' things that are children of the object the camera is on? If so:

 for (var t : Transform in Camera.main.transform)
   t.parent = null;
Comment
Add comment · Show 1 · 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 Halo500 · Sep 18, 2013 at 03:13 AM 0
Share

Sorry for not being clear. Yes, I would like to 'detach' the children of the $$anonymous$$ain Camera, which is also a child of the First Person Control Player.

Thank you for your answer that helped me INSTANTLY. This is why members of this community need people like you! :D

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

16 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

Related Questions

Transform.rotation is setting local rotatoin 0 Answers

Avoid scaling GameObject after parenting 2 Answers

Parent component affect child objects 0 Answers

Strange movement artifacts when rotating children around parent object 1 Answer

How to move a gameObject with another gameObject but slower 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