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 Kag359six · May 05, 2011 at 09:03 PM · parentingthroughunparenting

Temporary Parenting through Scripting

I have a script thats suppose to temporarily parent my object (player) to the animating elevator so it wont fall through the elevator as it goes up. then when its finished i want it to unparent it. however when i test it, it says that the variable "player" hasnt been assigned, even though i drag and dropped it into the player variable. heres my script:

var elevator : AnimationClip; //animation var player : GameObject; //object being parented to HoistCar

function OnTriggerEnter (myTrigger : Collider) {

if(myTrigger.gameObject.name == "player") { Debug.Log("elevator trigger activated"); //testing to see if trigger works HoistCar = GameObject.Find("HoistCar"); //finding gameobject player HoistCar.animation.Play("elevator"); //if trigger is activated, play //animation player.transform.parent = transform; //parent player to hoistcar if trigger is activated

     }
     else {
     transform.parent = null; //unparent object if animation isnt playing
     }

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by BinaryCore · May 05, 2011 at 11:57 PM

Did you drag and drop a Prefab of the player into your script variable in the designer? If so, you still need to call Instantiate to create an instance of your player or it won't exist yet at runtime.

A prefab is not an instance.

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 Joshua · May 06, 2011 at 02:22 AM 0
Share

I'd also guess that that might be it.

avatar image
0

Answer by demize2010 · May 06, 2011 at 01:33 AM

Hey man,

Consider using the "collision" info from trigger enter.

EG (not tested)

 function OnTriggerEnter (other : Collider) {
    other.transform.parent = transform; // You may need other.gameObject.transform.parent = transform;
}

You'll obviously need to drop that parenting onTriggerExit() or similar.

Comment
Add comment · Show 2 · 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 Kag359six · May 07, 2011 at 08:23 PM 0
Share

Thanks for the reply, but I'm trying to make it so when you get on the elevator, (when the animation starts from a trigger) i want the person to be parented to the elevator until the animation stops. this means if the player leaves the trigger, he will fall through the elevator since objects apparently don't stay on animating objects.

avatar image demize2010 · May 08, 2011 at 12:25 AM 0
Share

This will parent the transform of your character to the transform of the elevator which seems to be what you are after?

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

GetComponent for siblings and parents 2 Answers

Spawning Children and Destroying them. 1 Answer

Room Generator parenting issue 1 Answer

How can I access the children of a Transform? 5 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