检测按键输入,如果之前的方向不一样,则先销毁人物的GameObject对象,重新实例化。 if (Input.GetKey(KeyCode.A)) { if (!horizontal) { Vector3 pos = shanaSprite.transform.position; Destroy(shanaSprite); shanaSprite = Instantiate(shanaRollback, pos, Quaternion.identity); horizontal = true; } shanaSprite.transform.Translate(Vector3.left * Time.deltaTime * speed); }
检测按键输入,如果之前的方向不一样,则先销毁人物的GameObject对象,重新实例化。