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 Liban · May 15, 2012 at 02:20 AM · javascriptmodelsswap

Scripting help :D

Hey guys and gals!

In my game, my character has no legs at the beginning but later on has the chance to gain them back and become fully standing. For this I created two separate models of the character, one with legs and one without in hopes than I can swap between them.

The legless version would be replaced by the standing version permanently but I can't seem to get the script right. Here's what I have below;

 var legReplacementBolt: GameObject[]; 

 function OnCollisionEnter (collision : Collision)
     // Destroy enemy
     Destroy(gameObject);

     // Replace enemy with the dead body

     if(collision.gameObject.tag == "Player") {
         var legReplacementBolt: Transform = Instantiate(legreplacementbolt, transform.position, transform.rotation);
     // Copy position & rotation from the old hierarchy into the dead replacement
         CopyTransformsRecurse(transform, dead);
         return;
     }

 static function CopyTransformsRecurse (src : Transform, dst : Transform) {
 
     dst.position = src.position;
     dst.rotation = src.rotation;
 
     for (var child : Transform in dst) {
         // Match the transform with the same name
         var curSrc = src.Find(child.name);
         if (curSrc)
             CopyTransformsRecurse(curSrc, child);
         }
     }

Any help would be much appreciated :D Liban Ali

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 syclamoth · May 15, 2012 at 02:28 AM 0
Share

Is this your entire script? I just tried to fix the formatting, but it turns out that the script doesn't actually make any sense! $$anonymous$$ake sure you have the right number of open and close braces.

It looks like you've adapted this from a different script (probably one that automatically converts objects into other objects), but without really understanding why you have to do that. In your case, you should probably not use a script that recursively matches all the bones in a skeleton, because presumably you are using an animation on both (which will instantly wipe that match in the next frame).

avatar image KingCharizard · May 15, 2012 at 03:02 AM 0
Share

Is this your entire script? I just tried to fix the formatting, but it turns out that the script doesn't actually make any sense!

I agree with this I've read the script a few times I cannot understand it either. I don't like your variable na$$anonymous$$g either. What exactly is going wrong with the script, maybe if I knew what was wrong I'd knew where to look for the problem.

avatar image Liban · May 15, 2012 at 04:18 AM 0
Share

Ahh sorry about that! Here it is below; var BoltReplacement: Transform;

function OnTriggerEnter(hit : Collider) { // enemy hit by your sword if(hit.collider.tag == "playerswitch") { Destroy(gameObject); } if (BoltReplacement) { var dead : Transform = Instantiate(BoltReplacement, transform.position, transform.rotation); CopyTransformsRecurse(transform, dead); } if(!hit.collider.tag == "playerswitch") { return; } } static function CopyTransformsRecurse (src : Transform, dst : Transform) { dst.position = src.position; dst.rotation = src.rotation; }

I got it semi working however the big problem here is that when touching a collider seperate to the one tagged "playerswitch" the instantiate function is processed however the character model shows up 3 - 4 more times.,

avatar image bompi88 · May 15, 2012 at 08:28 AM 0
Share

@Liban. In comments, put your code inside pre and code brackets like this: \\

... code here ...

\\

avatar image KingCharizard · May 15, 2012 at 03:15 PM 0
Share

@Liban

""I got it semi working however the big problem here is that when touching a collider seperate to the one tagged "playerswitch" the instantiate function is processed however the character model shows up 3 - 4 more times.,""

This is because as long as your still in the collsision area the instantiate is being called. Try to make a variable that allows u to stop instantiate with a do while loop... so it does once but after the condition such as playerSwitched = true. Then stop the loop this way it will only run once and if the playerSwitched variable returns true it will break out the loop.

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.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

2D Modular Customization With Snapping 1 Answer

setup a php master server 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