Weapons are now in correct position

When u switch or pickup weapons u have them now in your hand.

- Scrollup doesnt work on the highest weapon index (will be fixed soon)
- Shooting with the hand will give an error because there is no animation "shoot" on the hand (PLEASE someone make an animation for the hand!!!!)
This commit is contained in:
Noah4ever
2021-11-29 11:22:03 +01:00
parent ad1e0cfeef
commit 59ff72d498
8 changed files with 157 additions and 119 deletions

View File

@@ -143,7 +143,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7365407325767981110}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.108, y: -0.084, z: 0.266}
m_LocalPosition: {x: 0.11501337, y: -0.084, z: 0.266}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
@@ -177,6 +177,8 @@ MonoBehaviour:
bulletExit: {fileID: 7365407325624913734}
allowAction: 1
weaponAnimator: {fileID: 7365407324475125414}
gunRightREF: {fileID: 2448190575139433570}
gunLeftREF: {fileID: 6708222704297240606}
--- !u!114 &3886275361998190322
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@@ -38,6 +38,7 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.0004, y: -0.01487, z: -0.143}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 732033708985862910}
m_RootOrder: 1
@@ -68,6 +69,7 @@ Transform:
m_LocalRotation: {x: -0, y: 0.7071068, z: 0.7071068, w: 0}
m_LocalPosition: {x: -0.03000002, y: -0.11399987, z: -0.42400002}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 732033708985862910}
m_RootOrder: 2
@@ -98,6 +100,7 @@ Transform:
m_LocalRotation: {x: -0, y: 0.7071068, z: 0.7071068, w: 0}
m_LocalPosition: {x: 0.030000005, y: -0.10400012, z: -0.42400002}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 732033708985862910}
m_RootOrder: 3
@@ -132,6 +135,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.03999999}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1584484548595912410}
- {fileID: 7502619830433694848}
@@ -176,6 +180,8 @@ MonoBehaviour:
bulletExit: {fileID: 2236875552107647873}
allowAction: 1
weaponAnimator: {fileID: 4836044225623250080}
gunRightREF: {fileID: 5792494204646893847}
gunLeftREF: {fileID: 808197646603973991}
--- !u!65 &3937508078766297979
BoxCollider:
m_ObjectHideFlags: 0

View File

@@ -493,7 +493,7 @@ MonoBehaviour:
playerController: {fileID: -4574526707603160507}
currentCameraRecoilX: 0
currentCameraRecoilY: 0
gunHolder: {fileID: 4484858123614617853}
gunHolder: {fileID: 4484858124469057131}
weaponManager: {fileID: 8357986889675898169}
positionRecoil: 1
rotationRecoil: 1
@@ -605,7 +605,7 @@ MonoBehaviour:
sceneId: 0
serverOnly: 0
visible: 0
m_AssetId: a14d876ac00bdf6498e30b3e58b68fdf
m_AssetId: 2935eead9a075fd489d6a6dc273a5999
hasSpawned: 0
--- !u!114 &7273209952621479910
MonoBehaviour:
@@ -744,7 +744,7 @@ MonoBehaviour:
activeWeapons:
- {fileID: 0}
- {fileID: 0}
- {fileID: 7365407325767981110, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
- {fileID: 4484858124469057131}
- {fileID: 0}
shoot: {fileID: 1258077278480047560}
gunHolster: {fileID: 6522444664664986769}
@@ -952,6 +952,42 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 48948dfe9d76b07488dacd46a7955fa1, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!95 &1978909962
Animator:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6576156620079053231}
m_Enabled: 1
m_Avatar: {fileID: 9000000, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_Controller: {fileID: 9100000, guid: bcfd120671431f84097ebc1045370f76, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_StabilizeFeet: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!114 &3855419186248803448
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6576156620079053231}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fff0960ef4ea6e04eac66b4a7fd2189d, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RigLayers:
- m_Rig: {fileID: 8865635171929772803}
m_Active: 1
m_Effectors: []
--- !u!1 &7061967201775281134
GameObject:
m_ObjectHideFlags: 0
@@ -1466,11 +1502,6 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 01316cb596562384da845bc519fb90de, type: 3}
--- !u!4 &8703533484509679896 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -5815427104119794202, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_PrefabInstance: {fileID: 6305701708507383038}
m_PrefabAsset: {fileID: 0}
--- !u!4 &5767109144009335573 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 01316cb596562384da845bc519fb90de, type: 3}
@@ -1481,11 +1512,6 @@ Transform:
m_CorrespondingSourceObject: {fileID: -6617984589164989631, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_PrefabInstance: {fileID: 6305701708507383038}
m_PrefabAsset: {fileID: 0}
--- !u!1 &6576156620079053231 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_PrefabInstance: {fileID: 6305701708507383038}
m_PrefabAsset: {fileID: 0}
--- !u!4 &5739201115059209923 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 1740614089614901821, guid: 01316cb596562384da845bc519fb90de, type: 3}
@@ -1496,6 +1522,11 @@ Transform:
m_CorrespondingSourceObject: {fileID: -4598867093515939143, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_PrefabInstance: {fileID: 6305701708507383038}
m_PrefabAsset: {fileID: 0}
--- !u!1 &6576156620079053231 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_PrefabInstance: {fileID: 6305701708507383038}
m_PrefabAsset: {fileID: 0}
--- !u!4 &9127245645273413481 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 2965664082145358743, guid: 01316cb596562384da845bc519fb90de, type: 3}
@@ -1506,42 +1537,11 @@ Transform:
m_CorrespondingSourceObject: {fileID: -5945183352512053224, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_PrefabInstance: {fileID: 6305701708507383038}
m_PrefabAsset: {fileID: 0}
--- !u!95 &1978909962
Animator:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
--- !u!4 &8703533484509679896 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -5815427104119794202, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_PrefabInstance: {fileID: 6305701708507383038}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6576156620079053231}
m_Enabled: 1
m_Avatar: {fileID: 9000000, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_Controller: {fileID: 9100000, guid: bcfd120671431f84097ebc1045370f76, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_StabilizeFeet: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!114 &3855419186248803448
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6576156620079053231}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fff0960ef4ea6e04eac66b4a7fd2189d, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RigLayers:
- m_Rig: {fileID: 8865635171929772803}
m_Active: 1
m_Effectors: []
--- !u!1001 &6343958082870406749
PrefabInstance:
m_ObjectHideFlags: 0
@@ -1555,7 +1555,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 2448190575139433570, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
propertyPath: m_LocalPosition.y
value: 0
value: -0.109999895
objectReference: {fileID: 0}
- target: {fileID: 2448190575139433570, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
propertyPath: m_LocalPosition.z
@@ -1567,11 +1567,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 6708222704297240606, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
propertyPath: m_LocalPosition.x
value: -0.105
value: -0.317
objectReference: {fileID: 0}
- target: {fileID: 6708222704297240606, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
propertyPath: m_LocalPosition.y
value: 0
value: -0.11
objectReference: {fileID: 0}
- target: {fileID: 6708222704297240606, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
propertyPath: m_LocalPosition.z
@@ -1641,9 +1641,18 @@ PrefabInstance:
propertyPath: m_IsKinematic
value: 1
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 3886275361998190322, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
--- !u!1 &4484858124469057131 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 7365407325767981110, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
m_PrefabInstance: {fileID: 6343958082870406749}
m_PrefabAsset: {fileID: 0}
--- !u!4 &8787644481610465855 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 2448190575139433570, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
m_PrefabInstance: {fileID: 6343958082870406749}
m_PrefabAsset: {fileID: 0}
--- !u!4 &365391085992511043 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 6708222704297240606, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
@@ -1654,18 +1663,8 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 7365407325624913734, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
m_PrefabInstance: {fileID: 6343958082870406749}
m_PrefabAsset: {fileID: 0}
--- !u!1 &4484858123614617853 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 7365407324475125408, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
m_PrefabInstance: {fileID: 6343958082870406749}
m_PrefabAsset: {fileID: 0}
--- !u!4 &4484858124469057129 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 7365407325767981108, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
m_PrefabInstance: {fileID: 6343958082870406749}
m_PrefabAsset: {fileID: 0}
--- !u!4 &8787644481610465855 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 2448190575139433570, guid: f1dd059fe90d9e14da7ad60b3612969c, type: 3}
m_PrefabInstance: {fileID: 6343958082870406749}
m_PrefabAsset: {fileID: 0}

View File

@@ -347,6 +347,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1351784394}
m_RootOrder: 2
@@ -383,6 +384,7 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -9.93, y: 5.64, z: 10.41}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1876458703}
m_RootOrder: 2
@@ -430,6 +432,7 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 4.12, y: 5.64, z: 11.09}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1876458703}
m_RootOrder: 3
@@ -479,6 +482,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -0.04, z: 0}
m_LocalScale: {x: 100, y: 0.1, z: 100}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1362549044}
m_RootOrder: 14
@@ -719,6 +723,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1351784394}
m_RootOrder: 4
@@ -871,6 +876,7 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.35, y: 5.64, z: -1.12}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1876458703}
m_RootOrder: 0
@@ -999,6 +1005,7 @@ Transform:
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
@@ -1187,6 +1194,7 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -10.37, y: 5.64, z: -1.75}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1876458703}
m_RootOrder: 1
@@ -1332,6 +1340,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1351784394}
m_RootOrder: 1
@@ -1441,6 +1450,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 10
@@ -1554,6 +1564,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1729968088}
- {fileID: 987854207}
@@ -1603,6 +1614,7 @@ RectTransform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1351784394}
m_RootOrder: 6
@@ -1737,6 +1749,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1351784394}
m_RootOrder: 3
@@ -1970,6 +1983,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.07, y: 0.07, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1351784394}
m_RootOrder: 5
@@ -2045,6 +2059,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1351784394}
m_RootOrder: 0
@@ -2196,6 +2211,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 5.94973, y: 3.086451, z: -1.6778176}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 655071530}
- {fileID: 753584349}
@@ -2296,6 +2312,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.5941708, y: -0.23374963, z: 0.91566634}
m_LocalScale: {x: 4.6584, y: 1, z: 14.388176}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
@@ -2355,6 +2372,10 @@ PrefabInstance:
propertyPath: m_Name
value: NetworkManager
objectReference: {fileID: 0}
- target: {fileID: 5784756223373504909, guid: 5cd2e2b44dc49ae44b48fc76a1e09712, type: 3}
propertyPath: playerPrefab
value:
objectReference: {fileID: 6272346181302961293, guid: 2935eead9a075fd489d6a6dc273a5999, type: 3}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 5cd2e2b44dc49ae44b48fc76a1e09712, type: 3}
--- !u!1001 &3454029965885532949
@@ -2441,6 +2462,10 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1430445131, guid: 6085e69ed0e6e364ca7dbdebfe7786c6, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8307265126920456896, guid: 6085e69ed0e6e364ca7dbdebfe7786c6, type: 3}
propertyPath: m_Pivot.x
value: 0

View File

@@ -102,6 +102,9 @@ public class ProcedualAnimationController : NetworkBehaviour
Vector3[] positionMod = new Vector3[3];
public Quaternion[] rotationMod = new Quaternion[3];
public Transform GunRightHandREF { get => gunRightHandREF; set => gunRightHandREF = value; }
public Transform GunLeftHandREF { get => gunLeftHandREF; set => gunLeftHandREF = value; }
public void walkAnimation()
{
playerAnimator.SetFloat("x", playerController.localVelocity.x / playerController.currentMaxSpeed);
@@ -119,10 +122,10 @@ public class ProcedualAnimationController : NetworkBehaviour
{
rightHandREF.position = defaultRightHandPosition;
}
if (gunLeftHandREF != null)
if (GunLeftHandREF != null)
{
leftHandREF.position = gunLeftHandREF.position;
leftHandREF.rotation = gunLeftHandREF.rotation;
leftHandREF.position = GunLeftHandREF.position;
leftHandREF.rotation = GunLeftHandREF.rotation;
}
else
{

View File

@@ -120,7 +120,6 @@ public class Shoot : NetworkBehaviour
}
public bool setWeapon(GameObject newWeapon) {
Debug.Log("SetWeapon: " + newWeapon);
weapon = newWeapon.GetComponent<Weapon>();
curAmmo = weapon.CurrentAmmunition;
totalAmmo = weapon.TotalAmmunition;

View File

@@ -20,6 +20,8 @@ public class Weapon : MonoBehaviour
[SerializeField] GameObject bulletExit;
[SerializeField] bool allowAction = true;
[SerializeField] Animator weaponAnimator;
[SerializeField] Transform gunRightREF;
[SerializeField] Transform gunLeftREF;
public bool Active { get => active; set => active = value; }
public weaponKinds WeaponKind { get => weaponKind; }
@@ -33,6 +35,8 @@ public class Weapon : MonoBehaviour
public GameObject BulletExit { get => bulletExit; }
public bool AllowAction { get => allowAction; set => allowAction = value; }
public Animator WeaponAnimator { get => weaponAnimator; }
public Transform GunLeftREF { get => gunLeftREF; }
public Transform GunRightREF { get => gunRightREF; }
private void Start()
{

View File

@@ -25,52 +25,44 @@ public class WeaponManager : NetworkBehaviour
void Update() {
if (isLocalPlayer) {
if(Input.GetAxis("Mouse ScrollWheel") > 0f){ // Scroll up
if (Input.GetAxis("Mouse ScrollWheel") > 0f) { // Scroll up
lastWeaponIndex = currentWeaponIndex;
int nextActive = SearchForNext(activeWeapons, lastWeaponIndex, -1);
if (nextActive != -1) { // -1 no next found
currentWeaponIndex = nextActive;
activeWeapons[currentWeaponIndex].SetActive(true);
procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex]);
shoot.setWeapon(activeWeapons[currentWeaponIndex]);
// play weapon switch animation
}
switchWeapon(-1);
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0f){ // Scroll down
else if (Input.GetAxis("Mouse ScrollWheel") < 0f) { // Scroll down
lastWeaponIndex = currentWeaponIndex;
int nextActive = SearchForNext(activeWeapons, lastWeaponIndex, 1);
if (nextActive != -1) { // -1 no next found
currentWeaponIndex = nextActive;
activeWeapons[currentWeaponIndex].SetActive(true);
procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex]);
shoot.setWeapon(activeWeapons[currentWeaponIndex]);
// play weapon switch animation
}
switchWeapon(1);
}
if (Input.GetButtonDown("Interact")) // e
{
PickupWeapon();
}else if (Input.GetButtonDown("Drop")) // q Droping weapon
{
if(activeWeapons[currentWeaponIndex] != null)
{
if (Input.GetButtonDown("Interact")) { // e
PickupWeapon();
}else if (Input.GetButtonDown("Drop")) { // q Droping weapon
if (activeWeapons[currentWeaponIndex] != null) {
dropWeapon(); // Throws weapon away
int nextActive = SearchForNext(activeWeapons, currentWeaponIndex, 1);
if (nextActive != -1) { // -1 no next found
currentWeaponIndex = nextActive;
activeWeapons[currentWeaponIndex].SetActive(true);
procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex]);
shoot.setWeapon(activeWeapons[currentWeaponIndex]);
// play weapon switch animation
}
switchWeapon(1);
}
}
}
}
private int SearchForNext(List<GameObject> l, int lastActive = 0, int direction = 1) {
private bool switchWeapon(int direction) {
int nextActive = searchForNext(activeWeapons, lastWeaponIndex, direction);
if (nextActive != -1) { // -1 no next found
currentWeaponIndex = nextActive;
activeWeapons[currentWeaponIndex].SetActive(true);
procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex]);
shoot.setWeapon(activeWeapons[currentWeaponIndex]);
Weapon weaponData = activeWeapons[currentWeaponIndex].GetComponent<Weapon>();
procedualAnimationController.GunRightHandREF = weaponData.GunRightREF;
procedualAnimationController.GunLeftHandREF = weaponData.GunLeftREF;
// play weapon switch animation
}
return false;
}
private int searchForNext(List<GameObject> l, int lastActive = 0, int direction = 1) {
int size = l.Count;
bool condition = true;
int counter = 0;
@@ -79,12 +71,24 @@ public class WeaponManager : NetworkBehaviour
if (lastActive <= -1) { lastActive = size; }
if (lastActive >= l.Count) { lastActive = 0; }
for (int i = lastActive + direction; condition; i += direction) {
if (i >= l.Count) { i = 0; size = lastActive; }
else if (i < 0) { i = size - 1; size = -1; }
if (i >= l.Count) {
i = 0; size = lastActive;
}
else if (i < 0) {
i = size - 1; size = -1;
}
Debug.Log("1 " + i);
if (l[i] != null) {
if (l[lastActive] != null) { l[lastActive].SetActive(false); }
if (l[lastActive] != null) {
l[lastActive].SetActive(false);
}
return i;
}
Debug.Log("2 " + i);
if (direction == 1) {
if (i <= size - 1) { condition = true; }
else { condition = false; }
@@ -94,19 +98,17 @@ public class WeaponManager : NetworkBehaviour
}
}
}
return -1;
}
public GameObject getCurrentWeapon()
{
public GameObject getCurrentWeapon() {
return activeWeapons[currentWeaponIndex].gameObject;
}
private void PickupWeapon() {
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit hit))
{
Debug.Log(hit.transform.name);
if (hit.transform.tag == "Weapon") // If Object is a weapon and the weapon is not in the current active weapons
{
foreach (GameObject obj in activeWeapons) { // Disable all weapons
@@ -116,7 +118,6 @@ public class WeaponManager : NetworkBehaviour
hit.rigidbody.isKinematic = true;
hit.rigidbody.useGravity = false;
hit.transform.GetComponent<BoxCollider>().enabled = false; // Disable Boxcollider
//hit.transform.position = cam.transform.position;
switch (hit.transform.GetComponent<Weapon>().WeaponKind.ToString()) { // Adding weapon to inventory slot
case "Rifle": putWeaponInArray(0, hit); break;
case "Pistole": putWeaponInArray(1, hit); break;
@@ -136,15 +137,15 @@ public class WeaponManager : NetworkBehaviour
activeWeapons[index].SetActive(true);
currentWeaponIndex = index;
procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex]);
Debug.Log(activeWeapons[currentWeaponIndex]);
shoot.setWeapon(activeWeapons[currentWeaponIndex]);
Weapon weaponData = activeWeapons[currentWeaponIndex].GetComponent<Weapon>();
procedualAnimationController.GunRightHandREF = weaponData.GunRightREF;
procedualAnimationController.GunLeftHandREF = weaponData.GunLeftREF;
return true;
}
private bool dropWeapon()
{
if(currentWeaponIndex != 2)
{
private bool dropWeapon() {
if(currentWeaponIndex != 2) {
GameObject currentWeapon = activeWeapons[currentWeaponIndex];
currentWeapon.SetActive(true);
Rigidbody rigid = currentWeapon.GetComponent<Rigidbody>();
@@ -157,8 +158,7 @@ public class WeaponManager : NetworkBehaviour
return true;
}
else
{
else {
return false;
}