打开CameraController在13行下面新建 public bool isAI = false;
在Awake函数里,增加判断条件,并把下列原先的代码放假判断式:
if(!isAI)
{
piCamera = Camera.main.gameObject;
lockDot.enabled = false;
Cursor.lockState = CursorLockMode.Locked;
}
FixUpdate函数里也做一样的操作:
if (!isAI)
{
piCamera.transform.position = Vector3.SmoothDamp(piCamera.transform.position,transform.position,ref cameraDampVelocity,cameraValue);
piCamera.transform.LookAt(cameraHandle.transform);
}
Update函数,在判断lockTarget是否为空的判断式里添加:
if (!isAI)
{
lockDot.rectTransform.position = Camera.main.WorldToScreenPoint(lockTarget.obj.transform.position + new Vector3(0, lockTarget.halfHeight, 0));
}
封装了一个函数在Update函数下面:
private void LockProcessA(LockTarget _lockTarget,bool _lockDotEnable, bool _lockState, bool _isAI)
{
lockTarget = _lockTarget;
if (!isAI)
{
lockDot.enabled = _lockDotEnable;
}
lockState = _lockState;
}
把前面有用到lockTarget,lockDot.enabled还有lockState的代码,都更换成函数并写入参数:
LockProcessA(null,false,false,isAI);
LockUnlock函数里,foreach里面的代码修改成:
if (lockTarget != null && lockTarget.obj == col.gameObject)
{
LockProcessA(null, false, false, isAI);
break;
}
LockProcessA(new LockTarget(col.gameObject, col.bounds.extents.y), true, true, isAI);
break;
运行时候发现52行报错:
需要将Awake函数改成Start函数。
标签:false,函数,isAI,transform,摄像机,lockState,黑魂,lockTarget,复刻 From: https://www.cnblogs.com/dontpanic1703/p/17564137.html