I am looking for a simple way, either using an animator or through direct script, to set a single sprite for certain actions that occur with my character.
For example, character gets hurt, set sprite to hurtsprite. Character gets frozen, set sprite to frozensprite.
(These are just examples. My original game is built in Game Maker, and has been worked on for the past 10 years. I am porting it, so obviously these interactions are going to be much more complicated down the road).
Currently I’ve set up a basic animator with two frames for testing out. I’ve managed to lock it on the first frame by setting, in my character controller script:
private Animator anim;
anim = GetComponent();
anim.speed = 0;
If I try using
anim.playbackTime = 1;
to show the second frame, it says it’s not in playback mode, and if I put it in playback mode, it says there’s no recording to play back, so obviously this is not the correct way to do it.
I can’t seem to find the value to set to change the frame. I put the animation rate at “1”, so each frame of the animation is a second long, just to try to make it easier for me to go “I want the third frame, so let me set it to time 2” (assuming it counts 0, 1, 2, …) but so far that’s as far as I’ve gotten.
All of the info and demos I’ve found are for older versions of Unity (I’m using 5.5) and the functions they use are all deprecated.
I’m trying to build my game using only the default free version of Unity. (I know there are paid add-ons that give me much greater 2D sprite control).
Figured it out. This method does not use the animator object (though I may need it later on for some things).
The sprites have to reside under the “Assets/Resources” folder. It won’t work otherwise. I tried using my own folder name for the Resources folder, but it only wants to use “Resources”
In the main public class definition for my character controller, I have these lines