为什么 Unity 不允许我为 Sprite 使用动画?
Why Won't Unity Let Me Use Animation For My Sprite?
我正在为我的游戏制作倒数计时器,我需要为精灵设置动画:“3”、“2”、“1”、"Go!"。我确切地知道如何制作该动画,所以这不是我的问题。我的问题是:为什么 Unity 不让我 select 所有 4 个精灵并为它们制作动画?
如果您需要更多信息或其他图片,请告诉我。谢谢! :)
您不为 sprite 设置动画,而是使用 Sprite 为组件 (SpriteRenderer) 设置动画。精灵是具有某些特殊属性的纹理,因此被专门考虑。
您不需要为纹理设置动画,它只是一个图像,您有一组交换纹理以创建动画效果。
如果你想为你的 3-2-1-Go 设置动画,你首先需要创建一个 Sprite 游戏对象,然后为其分配一个精灵纹理,然后创建一个 Animator 和一个 Animation 剪辑。
您的动画会在特定时间交换当前纹理,很可能与动画事件有关。
实际上,通过脚本来做可能更容易:
// Drag sprites, make sure they are in order (3->2->1->Go)
public Sprite[] sprites;
public SpriteRenderer sp;
int index = 0;
void Start()
{
// Check your sprites and sp
InvokeRepeating("SwapSprite", 1.0f,1.0f); // Start timer to swap each second
sp.sprite = sprites[index]; // Set initial sprite
}
private void SwapSprite()
{
if(++index == sprites.Length) // Increase the index and check we run out of sprites
{
CancelInvoke();
sp.enabled = false; // Remove the counter
this.enabled = false; // That scripts is no more useful (could be destroyed)
return;
}
sp.sprite = sprites[index]; // Set new sprite
}
我正在为我的游戏制作倒数计时器,我需要为精灵设置动画:“3”、“2”、“1”、"Go!"。我确切地知道如何制作该动画,所以这不是我的问题。我的问题是:为什么 Unity 不让我 select 所有 4 个精灵并为它们制作动画?
如果您需要更多信息或其他图片,请告诉我。谢谢! :)
您不为 sprite 设置动画,而是使用 Sprite 为组件 (SpriteRenderer) 设置动画。精灵是具有某些特殊属性的纹理,因此被专门考虑。
您不需要为纹理设置动画,它只是一个图像,您有一组交换纹理以创建动画效果。
如果你想为你的 3-2-1-Go 设置动画,你首先需要创建一个 Sprite 游戏对象,然后为其分配一个精灵纹理,然后创建一个 Animator 和一个 Animation 剪辑。
您的动画会在特定时间交换当前纹理,很可能与动画事件有关。
实际上,通过脚本来做可能更容易:
// Drag sprites, make sure they are in order (3->2->1->Go)
public Sprite[] sprites;
public SpriteRenderer sp;
int index = 0;
void Start()
{
// Check your sprites and sp
InvokeRepeating("SwapSprite", 1.0f,1.0f); // Start timer to swap each second
sp.sprite = sprites[index]; // Set initial sprite
}
private void SwapSprite()
{
if(++index == sprites.Length) // Increase the index and check we run out of sprites
{
CancelInvoke();
sp.enabled = false; // Remove the counter
this.enabled = false; // That scripts is no more useful (could be destroyed)
return;
}
sp.sprite = sprites[index]; // Set new sprite
}