- Home /
Script or Animation,which is best for performance?
I have an object in my game that I want to spin constantly. At times (not always) there may be several of these in one scene. I have a very simple script that does the job at the moment-
#pragma strict
var spinx : int = 0;
var spiny : int = 3;
var spinz : int = 0;
function Update ()
{
transform.Rotate(spinx,spiny,spinz);
}
OR... would I be better off using an animation? Which is going to be the more efficient option?
Answer by Haseeb_BSAA · Jan 17, 2015 at 06:27 PM
The best option will be the one that suits your game. If rotating by script is just as fine as an animation then script will be a better option since you don't have to worry about keyframe problems and the movement will be steady! But if that doesn't look good with script , go for animation.
Function Update will keep rotating the object in all 60 frames of your game. If you write animation.Play("Name"); In the Function Update , it really wouldn't make any difference since it will play the animation in 60 frames as well. The choice is yours :)
This does not really answer the root question: which is more efficient? (then again, I'm interpreting "efficient", as faster, rather than easier to code.)
if you use Time.Framerate%=N, then it will be every N frame it play the animation. It won't help if you have to do fast rotation cause you have to rotate this much frame.But still, scripting allow you adjust parameters easer. $$anonymous$$ore control means you have choice. Animation is simpler way but not flexible.
Its not about the extent we can utilize it, its about which will have less load on the system i.e. "efficient" while playing.
Your answer
![](https://koobas.hobune.stream/wayback/20220613180653im_/https://answers.unity.com/themes/thub/images/avi.jpg)