无法从“对象”转换为“ UnityEngine.Vector2”

时间:2019-08-09 20:10:43

标签: c# unity3d

我正在创建一个游戏,我在对瞄准机制进行编码时遇到问题,而在“偏移”方面却遇到了问题。
这是我得到的错误: “错误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);
        }
    }

1 个答案:

答案 0 :(得分:1)

offset创建为Vector2

Vector2 offset = cc.isCrouching ? CurrentWeapon.headTrackOffsetCrouch : CurrentWeapon.headTrackOffset;

还将headTrackOffsetCrouchheadTrackOffset定义为Vector2

public Vector2 headTrackOffsetCrouch;

public Vector2 headTrackOffset;