- Home /
Question by
WaxOcelot · Apr 16 at 04:08 AM ·
gameobjectposition
How could I make a gameobject move above my players head during an animation and then delete it?
I have a script that plays an animation when walking into an item while also playing a sound effect. How could I make it move above my head and then disappear, like in this image?
screenshot-2022-04-16-000617.png
(20.2 kB)
Comment
Answer by maross334 · Apr 16 at 04:22 AM
You can start a coroutine that activates your gameobject to hold over-head, then wait for the animation clip length. After animation length seconds, you deactivate the item
void GiftPlayer(){
anim.SetBool("award", true);
StartCoroutine(HeldItem(diamond)); // starts a coroutine that waits for animation length
}
IEnumerator HeldItem(GameObject aItem){
aItem.SetActive(true);
yield return new WaitForSeconds(awardClipLength); // wait for length of animation
aItem.SetActive(false);
}
Make sure the item is parented to the player, and it will follow your player.