- Home /
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
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).
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.
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.,
""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.
Your answer
Follow this Question
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