[英]Unity sprite is show before position is changed
I have six or more sprites that are hidden, alpha set to 0. I move the sprites to a starting position at the top of the screen before showing them.我有六个或更多隐藏的精灵,alpha 设置为 0。在显示它们之前,我将精灵移动到屏幕顶部的起始 position。 Once in the new position I show them and the moving them back to their original positions.一旦进入新的 position,我会展示它们并将它们移回原来的位置。
My issue is that the sprites are show just for a couple of milliseconds before they are moved to the starting point.我的问题是精灵在移动到起点之前仅显示几毫秒。 Even though the order of the code is move first then show.即使代码的顺序是先移动然后显示。
I tried to find a position moved callback to detect when the position change is complete before showing but I don't this it is possible.我试图找到一个 position 移动回调来检测 position 更改何时在显示之前完成,但我不认为这是可能的。
void Start() {
int i = 0;
foreach (Transform point in drawingPoints.transform)
{
//Record points original postion
Vector3 currentPosition = point.transform.position;
//Move to new starting position
point.transform.position = stepOne.transform.position;
//Now show point
var color = point.gameObject.GetComponent<SpriteRenderer>().color;
color.a = 1;
point.gameObject.GetComponent<SpriteRenderer>().color = color;
//Move point back to original postion
point.transform.DOMove(currentPosition, 1f).SetDelay(UnityEngine.Random.Range(0f, 0.3f));
i += 1;
}
}
Consider disabling the sprite renderer till the transform is at the start point.考虑禁用精灵渲染器,直到变换位于起点。
void Start()
{
int i = 0;
foreach (Transform point in drawingPoints.transform)
{
SpriteRenderer spriteRenderer = point.gameObject.GetComponent<SpriteRenderer>();
if(spriteRenderer == null)
continue;
// Disable the renderer.
spriteRenderer.enabled = false;
//Record points original postion
Vector3 currentPosition = point.transform.position;
//Move to new starting position
point.transform.position = stepOne.transform.position;
// Now you're at start point, enable it back.
spriteRenderer.enabled = true;
//Move point back to original postion
point.transform.DOMove(currentPosition, 1f).SetDelay(UnityEngine.Random.Range(0f, 0.3f));
i += 1;
}
}
If for whatever reason or weird behaviour of unity you wanna get a callback when something is at a position, here's a hacky way如果出于某种原因或奇怪的团结行为,当某物位于 position 时,您想获得回调,这是一种 hacky 方式
transformToMove.DoMove(destination, 0).OnComplete(()=>
{
// Now you're at the point.
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.