using System.Collections; using System.Collections.Generic; using UnityEngine; public enum GunType { Rifle, MusketRifle, Pistol, Sniper, Shotgun, } public class PlayerArms_IK : MonoBehaviour { public FastIKFabrics rightHandIK; public FastIKFabrics leftHandIK; public Transform rightArmTransform; public Transform leftArmTransform; public GunType equippedGunType; // for inspector changing [SerializeField] private bool updateGunOffsets; // for inspector changing in-game, acts as a trigger private readonly Dictionary armOffsetDict = new Dictionary(); private void Awake() { InitArmOffsets(); } private void InitArmOffsets() { Vector3 rightArmRiflePosition = new Vector3(0.065f, 0.021f, -0.786f); //these are not final. Vector3 leftArmRiflePosition = new Vector3(-0.023f, -0.134f, -0.396f); Vector3 rightArmPistolPosition = new Vector3(0.223f, -0.108f, -0.7f); Vector3 leftArmPistolPosition = new Vector3(0.507f, 0.09f, -1.109f); //off screen. so only 1 handed pistol. Vector3 rightArmSniperPosition = new Vector3(0.128f, -0.066f, -0.799f); Vector3 leftArmSniperPosition = new Vector3(0.053f, -0.06f, -0.5581f); Vector3 rightArmMusketPosition = new Vector3(0.065f, -0.247f, -0.791f); Vector3 leftArmMusketPosition = new Vector3(-0.025f, -0.223f, -0.489f); Vector3 rightArmShotgunPosition = new Vector3(0.066f, 0.02f, -0.757f); Vector3 leftArmShotgunPosition = new Vector3(-0.024f, -0.133f, -0.454f); armOffsetDict.Add(GunType.Rifle, new Vector3[] { rightArmRiflePosition, leftArmRiflePosition }); //first is right arm, second is left arm. armOffsetDict.Add(GunType.Pistol, new Vector3[] { rightArmPistolPosition, leftArmPistolPosition }); armOffsetDict.Add(GunType.Sniper, new Vector3[] { rightArmSniperPosition, leftArmSniperPosition }); armOffsetDict.Add(GunType.MusketRifle, new Vector3[] { rightArmMusketPosition, leftArmMusketPosition }); armOffsetDict.Add(GunType.Shotgun, new Vector3[] { rightArmShotgunPosition, leftArmShotgunPosition }); } public void UpdateArmOffsets() { rightArmTransform.localPosition = armOffsetDict[equippedGunType][0]; //right arm leftArmTransform.localPosition = armOffsetDict[equippedGunType][1]; //left arm } private void Update() { if (updateGunOffsets) { UpdateArmOffsets(); updateGunOffsets = false; } } }