Hello, I'm new on unity and I want to animate the menu when it appear. There is my menu, and the animation that I wanna make. I try using mask but it did'nt work. Thank to help me and sorry for the bad english, I'm french.
@Slave23 you have a few ways of tackling that. As this is a pretty simple animation you could do it using a script or using an AnimationController with an Animation for example. Following are two examples on how to achieve this using those two ways: Using Animation: Using Script: Following the script I created for this: Code (CSharp): using System.Collections; using UnityEngine; public class OpenMenu : MonoBehaviour { [SerializeField] [Tooltip("The time it takes to open the menu in seconds")] private float openingTime = 1f; private Vector3 startSize; private Vector3 endSize; /// <summary> /// Executed at the first frame /// Saves the scale of the menu (should have a zero value of x) the script is on into startSize /// and sets endSize based on it to later animate from startSize to endSize /// </summary> private void Start() { startSize = transform.localScale; endSize = new Vector3(1, startSize.y, startSize.z); } /// <summary> /// Starts the coroutine which opens the menu /// </summary> public void Open() { StartCoroutine(OpenCoroutine()); } /// <summary> /// Animates the size of the menu over openingTime seconds from startSize to endSize using Vector3.Lerp /// </summary> /// <returns></returns> private IEnumerator OpenCoroutine() { float elapsedTime = 0f; while (elapsedTime < openingTime) { transform.localScale = Vector3.Lerp(startSize, endSize, elapsedTime / openingTime); elapsedTime += Time.deltaTime; yield return null; } transform.localScale = endSize; } } If you have any questions, please do not hesitate to ask. Greetings Roy
Wow ! Thank you for the time you spent for me but I had already tested this by animating and it didn't work since my image isn't a solid color. It's look pretty anwful : And for the mask, I try like this but the problem are I can start the mask at the center of the image and if I set the alpha to 0 all my image is gone :/
In that case you can animate the Rect size instead of the object size. Here an example: If you need help on how to animate that, please ask.