【发布时间】:2020-09-08 16:30:04
【问题描述】:
(二维) 我正在制作一个小型原型并尝试使用当玩家进入触发器时从一个位置移动到另一个位置的相机进行试验。 但它只是简单地将相机 z 位置设为 0 并将其稍微向右移动。
它还给了我错误“(8,22):警告CS0108:'endLevel.camera'隐藏了继承的成员'Component.camera'。如果打算隐藏,请使用新关键字。”但我不知道如何解决这个问题。
脚本附加到触发器对象。
public class endLevel : MonoBehaviour
{
public Transform camera;
public Transform rightPoint;//spot camera moves towards on the right
public Transform leftPoint;//spot on the left
public float speed;
void OnTriggerEnter2D ()
{
if(camera.position == leftPoint.position)
{
camera.position = Vector2.Lerp(leftPoint.position, rightPoint.position, speed * Time.deltaTime);//initially used MoveTowards and still failed
}else if(camera.position == rightPoint.position)
{
camera.position = Vector2.Lerp(rightPoint.position, leftPoint.position, speed * Time.deltaTime);//initially used MoveTowards and still failed
}
}
}
【问题讨论】: