- Home /
Question by
tranhiepvn · Mar 24, 2017 at 04:39 AM ·
animationspritecoordinatesscreenspacecapture
unity gameobject to sprite (UI Image)
My scene has a gameobject (a prefab with animations) which plays animations by calling the CrossFade() function, when the animation finished. I would like to capture this "picture" gameobject as image to assign it as a sprite of the Image UI (on canvas screenspace) and do some animation (move around the screen) with this UI Image. How can I do this?
Comment
Answer by SohailBukhari · Mar 24, 2017 at 06:40 AM
Declare field for sprite and image.
using UnityEngine;
using UnityEngine.UI;
public class UiSpriteChange : MonoBehaviour
{
[SerializeField]private Image Myimage;
[SerializeField]private Sprite MySprite;
// Use this for initialization
void Start ()
{
if (Myimage != null) Myimage.GetComponent<Image>().overrideSprite = MySprite;
}
}