Change multiple sprite in one animation clip
Solution 1
So i already figured out. All I have to do is using lateupdate function and make the "sign" object follow the "boy" object, then make simple animation in "sign" object
public Transform target;
public Transform sign;
public float xOffset;
public float zSignOffset;
void LateUpdate(){
sign.transform.localPosition = new Vector3 (target.localPosition.x+ xOffset, transform.localPosition.y, target.localPosition.z+ zSignOffset);
}
Solution 2
You can create an animation by simply dragging a series of images to the "hierarchy" window as: boyChips0001.png boyChips0002.png boyChips0003.png
When you do this, Unity will automatically create a new GameObject with a "Animator Controller" and an "Animation" attached to it.
You can delete the GameObject and the animator controller if you want, what matters is the animation, with the extension ".anim".
You can create as many files ".anim" as you need in the same way.when you have all you need, it's time to link to your object. To do that, add a new "Animator" by pressing the "Add component" button in the Inspector and typing "Animator".
Then, create a controller Animator clicking on the "create" button on the "project" window and selecting "Animator controller"
Now, asign the animator controller to the animator.
Open the Animator window selecting the menu "window/Animator" with the Animator controller selected or by double click on its Animator Controler
Finally drag and drop your animations created to this animator window
Now, your animations are ready to be used by a script. For example, the next code cycle between the animations when the user hits the space bar:
public class TransitionScript : MonoBehaviour {
public GameObject Globe;
string[] AnimationName;
private int currentAnimation;
KeyCode key;
// Use this for initialization
void Start () {
currentAnimation = 0;
AnimationName = new string[3];
AnimationName[0] = "Repose";
AnimationName[1] = "Globe1 Animation";
AnimationName[2] = "Glove2 Animation";
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
print("space Down");
Animator anim = Globe.GetComponent<Animator>();
currentAnimation++;
if (currentAnimation >= AnimationName.Length) currentAnimation = 0;
anim.Play(AnimationName[currentAnimation]);
}
}
}
Note: The animated gameObject must have a Sprite Renderer component. If not, you can not see the animation:
Comments
-
Eeva almost 2 years
Lets say that i have two animation clip, idle and action; and two spritesheet, a boy and sign. I want boy and sign sprite animated from the same animation clip because i already made separate sprite for that. This is sign spritesheet
And this is boy spritesheet
I want my animation clip consist of two animated sprite like this
I don't want make two animator (for both boy and sign) because my animator is so complicated and make two will take really long time. thanks
ps. sorry english is not my home language :)