我正在尝试制作以下相机平移 js 脚本,使其正常工作,这意味着左右平移相机。到目前为止,我所做的是将相机仅向左移动并返回其起始位置。我无法让它在被点击/触摸的 gui.button 上左右移动。
这是js脚本:
#pragma strict
var target : GameObject;
var xpositionLeft = 10;
var xpositionRight = -10;
//var smooth : float = 5; // Don't know where should I put this var to make it pan smooth?
private static var isPanning = false;
function Update()
{
if(isPanning == true)
{
transform.position.x = target.transform.position.x;
transform.position.x = xpositionLeft;
}
else
{
transform.position.x = target.transform.position.x; // It only pan the camera left, not right!
transform.position.x = xpositionRight;
}
}
static function doPanning ()
{
isPanning = !isPanning;
}
有人可以提供有关如何使此脚本正常工作的线索吗?我是 Unity 和编程的新手,因此非常欢迎任何帮助。提前感谢大家的时间和答案。