【发布时间】:2020-09-02 10:03:02
【问题描述】:
我在 Unity 上制作 2D 游戏,但渲染和移动顺序有问题。 我有一个脚本制作平台,当玩家踩到它时会掉落并消失。这是我的脚本的主要部分:
void OnCollisionEnter2D (Collision2D col)
{
if (col.gameObject.name.Equals("Player") && player.GetComponent<PlayerController>().IsGrounded() && !platformMovingBack)
{
Invoke ("DropPlatform", 1f);
}
}
void DropPlatform()
{
rb.isKinematic = false;
Invoke("DestroyPlatform", 0.4f);
Invoke ("GetPlatformBack", 1.4f);
Invoke("ResurrectPlatform", 2f);
}
void GetPlatformBack()
{
rb.velocity = Vector2.zero;
platformMovingBack = true;
}
void DestroyPlatform()
{
transform.gameObject.SetActive(false);
}
void ResurrectPlatform()
{
rb.isKinematic = true;
transform.gameObject.SetActive(true);
}
void Update()
{
if (platformMovingBack)
{
transform.position = initialPosition;
transform.rotation = initialRotation;
platformMovingBack = false;
}
}
但是我有一个问题。尽管平台在所有执行后才变得活跃,但在游戏中我看到平台摇晃并向上移动。我做错了什么?
【问题讨论】: