我有一个 Unity Slidepuzzle 游戏(4x4),我检查开放区域要移动到哪里。我尝试使用 MoveTowards 制作幻灯片动画,效果很好,但现在我遇到的问题是,当我单击开放空间旁边的两块(快速)时,两者都会移入其中,因为该块不完全在那里,因此光线无法移动打任何东西。PS:它可以在没有动画的情况下工作,但我只是不希望这些碎片只是传送。我想要一个平滑的幻灯片。
我尝试用布尔值解决它,这样当我单击它时,移动设置为 true,当动画完成时再次设置为 false,但这不起作用。
void MovePuzzle()
{
float duration = 0.5f;
if(go_left)
{
Vector3 endPos1 = new Vector3(transform.position.x - move_amount.x, transform.position.y, transform.position.z);
StartCoroutine(MoveTowards(endPos1, duration));
go_left = false;
moved = true;
}
if (go_right)
{
Vector3 endPos2 = new Vector3(transform.position.x + move_amount.x, transform.position.y, transform.position.z);
StartCoroutine(MoveTowards(endPos2, duration));
go_right = false;
moved = true;
}
if (go_up)
{
Vector3 endPos3 = new Vector3(transform.position.x, transform.position.y + move_amount.y, transform.position.z);
StartCoroutine(MoveTowards(endPos3, duration));
go_up = false;
moved = true;
}
if (go_down)
{
Vector3 endPos4 = new Vector3(transform.position.x, transform.position.y - move_amount.y, transform.position.z);
StartCoroutine(MoveTowards(endPos4, duration));
go_down = false;
moved = true;
}
}
IEnumerator MoveTowards(Vector3 toPosition, float duration)
{
float counter = 0;
while (counter < duration)
{
counter += Time.deltaTime;
Vector3 currentPos = transform.position;
float time = Vector3.Distance(currentPos, toPosition) / (duration - counter) * Time.deltaTime;
transform.position = Vector3.MoveTowards(currentPos, toPosition, time);
Debug.Log(counter + " / " + duration);
yield return null;
}
}
在幻灯片动画完成之前是否有办法限制点击?我对 Unity 还比较陌生,所以不要指望我能提供太多知识 :D。
白猪掌柜的
相关分类