我有一个难题。我正在尝试做类似的事情:我有 3 个按钮,我点击一个,它增加,我点击另一个,它增加,前一个返回到原始大小。
private void PigeonholesHasClicked(GameObject target, MouseEventType type)
{
if (type == MouseEventType.CLICK)
{
TargetIndex = System.Array.IndexOf(Pigeonholes, target);
PigeonholesTrasnform();
}
}
Vector3 mPosition;
int lastIndex = 0;
public float mIndex;
private void PigeonholesTrasnform()
{
mPosition = new Vector3(Pigeonholes[TargetIndex].transform.position.x - mIndex, Pigeonholes[TargetIndex].transform.position.y, 0f);
Pigeonholes[TargetIndex].transform.DOMove(mPosition, 0.5f);
Pigeonholes[TargetIndex].GetComponent<BoxCollider2D>().enabled = false;
if (TargetIndex != lastIndex)
{
mPosition = new Vector3(Pigeonholes[lastIndex].transform.position.x + mIndex, Pigeonholes[lastIndex].transform.position.y, 0f);
Pigeonholes[lastIndex].transform.DOMove(mPosition, 0.5f);
for (int i = 0; i < Pigeonholes.Length; i++)
{
if (i != TargetIndex)
Pigeonholes[i].GetComponent<BoxCollider2D>().enabled = true;
}
}
lastIndex = TargetIndex;
}
问题是,如果我点击 1 或 2 按钮,0 按钮会向右移动 0.4。如果我先开始输入 0,然后按 1 或 2,那么一切正常。想法是 lastIndex 为 0最初,如果我把它设为-1,它会给我一个错误。帮助!!!
撒科打诨
相关分类