我正在创建一个游戏,我在对瞄准机制进行编码时遇到问题,而在“偏移”方面却遇到了问题。
这是我得到的错误:
“错误CS1503:参数2:无法从'对象'转换为'UnityEngine.Vector2'”
protected virtual void UpdateHeadTrack()
{
if (!shooterManager || !headTrack)
{
if (headTrack) headTrack.offsetSpine = Vector2.Lerp(headTrack.offsetSpine, Vector2.zero, headTrack.smooth * Time.deltaTime);
return;
}
if (!CurrentWeapon || !headTrack)
{
if (headTrack) headTrack.offsetSpine = Vector2.Lerp(headTrack.offsetSpine, Vector2.zero, headTrack.smooth * Time.deltaTime);
return;
}
if (isAiming || aimTimming > 0f)
{
object offset = cc.isCrouching ? CurrentWeapon.headTrackOffsetCrouch : CurrentWeapon.headTrackOffset;
headTrack.offsetSpine = Vector2.Lerp(headTrack.offsetSpine, offset, headTrack.smooth * Time.deltaTime);
}
else
{
headTrack.offsetSpine = Vector2.Lerp(headTrack.offsetSpine, Vector2.zero, headTrack.smooth * Time.deltaTime);
}
}
答案 0 :(得分:1)
将offset
创建为Vector2
:
Vector2 offset = cc.isCrouching ? CurrentWeapon.headTrackOffsetCrouch : CurrentWeapon.headTrackOffset;
还将headTrackOffsetCrouch
和headTrackOffset
定义为Vector2
:
public Vector2 headTrackOffsetCrouch;
public Vector2 headTrackOffset;