我试着制作一台只在特定时间移动的相机,但失败得很惨



(2D(我正在制作一个小原型,并尝试用一台相机进行实验,当玩家按下扳机时,相机会从一个位置移动到另一个位置。但它只是简单地使相机z位置为0,并将其稍微向右移动。

它也给了我一个错误";(8,22(:警告CS0108:"endLevel.camera"隐藏继承的成员"Component.cacamera"。如果要隐藏,请使用new关键字"但我不知道该怎么解决。

脚本附加到触发器对象。

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
}
}
}

这意味着MonoBehaviour已经有一个名为camera的属性。所以添加public Transform camera会隐藏它。

您的类继承自MonoBehaviour,因此您可以从Monobehaviour访问公共属性

你不必在课堂上添加public Transform camera

最新更新