Reputation:
This might be a silly question, but I was wondering if there maybe a way of programatically changing something in a Unity project (i.e. via code) so that when you press play
, before it actually runs, that change takes place, as if you manually changed it before you ran it.
Here is why I am asking this (potentially stupid) question: I have a character that will do something in 2 different scenarios. So, the user selects one of two toggles to indicate scenario 1 or 2
The problem is, in one of the scenarios, I have to adjust the initial T-pose of the character for it to be animated properly. So, in scenario one, I just run it and everything is fine, but in scenario two, I first have to correct the orientations of the shoulder joints using the mouse and Unity's rotate
tool, to put the character in a precise T-pose, before running.
But whatever orientation I specify in a script will, of course, be applied when I run the app, not beforehand in the Unity Editor. So I wonder if I could somehow hard-code this change in a script, so that it all seems to be automatic and professional, based on which scenario is chosen. Is such a thing possible at all?
Upvotes: 0
Views: 1207
Reputation: 12592
Things like this can be tricky working in the Editor. As you say, you often in practice -- just during development -- need to do something "automatically every time" when you hit Play.
For example, http://answers.unity3d.com/questions/441246/editor-script-to-make-play-always-jump-to-a-start.html
So in a sense the answer to your question is learn editor scripting which is a bit of an art in itself.
In your specific example: really what I would do is this.
1) take the character in question
2) duplicate it
3) on the second one, set it up for the "other" situation
Now mark them both inactive. When you launch have a script which
SetActive(true)
on only the one you need.
Note that in general, with characters. It's extremely common, universal, that you have "more than one" version of the character. So you might have the normal character, the ragdoll character, the character for climbing in to the car, and so on. For substantially different locomotions and stuff you may have different versions of the characetr .. say, one for normal walking/running etc and one for "climbing the cliff" and one for crawling-related actions.
so it's normal/usual that for a character you actually have a few different ones. Have a routine that selects only one of them to be active. And then you will see lots of code like this ..
if ( freddy .blownUpInExplosion)
freddy.ChangeToPuppet( "oneLimbVersion" );
you know?
So indeed that will solve your problem here - in short, hit Apple-D and duplicate the character. Set the "other one" up the "other way". You're off to the races.
Upvotes: 2