我正在使用Raycast制作RTS动态相机,但我造成了这些问题:
1. Assets/CameraMover.js(11,73): BCE0044: expecting ), found 'hit'.
2. Assets/CameraMover.js(11,77): BCE0043: Unexpected token: ).
代码如下所示:
var RaycastHit : hit;
if(Physics.Raycast(Transform.position, -Transform.position, out hit)){
curDistance = Vector3.Distance(Transform.position, hit.point);
}
if(curDistance != cameraDistance){
var difference = cameraDistance - curDistance;
Transform.position = Vector3.Lerp(Transform.position, Transform.position + new Vector3(0, difference, 0), Time.deltaTime);
}
答案 0 :(得分:0)
您将out hit
作为第三个参数传递给Physics.Raycast
,但函数签名为:
public static bool Raycast(Vector3 origin, Vector3 direction, float distance = Mathf.Infinity, int layerMask = DefaultRaycastLayers);
实际上,您需要移除, out hit
,或将其更改为表示您想要进行射线测试的最大距离的浮点数。
答案 1 :(得分:0)
好吧,我现在就像@Adam Harwood一样,但是当位置稳定时,它会振动。
var hit : RaycastHit;
var curDistance : float;
if (Physics.Raycast(transform.position, -transform.position, hit)){
curDistance = Vector3.Distance(transform.position, hit.point);
}
if(curDistance != cameraDistance){
var difference = cameraDistance - curDistance;
transform.position = Vector3.Lerp(transform.position, transform.position + new Vector3(0,difference,0), Time.deltaTime);
}