Weapon Switching/pickup/throw

[+] added
+ added pickup weapons
+ added throw weapons
+ added weapon switching
+ scrolling searches for next active weapon

[n] needs to be added
n weapon in correct position after pickup
n after weapon throw -> next active weapon needs to be equipt
n throw/pickup/switch weapon animation
This commit is contained in:
Noah4ever
2021-11-20 15:47:58 +01:00
parent facc42b03f
commit a40aec3874
6 changed files with 256 additions and 118 deletions

View File

@@ -169,7 +169,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7014992348987952529}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.0594, y: 0.123, z: 0}
m_LocalPosition: {x: -0.003, y: 0.04, z: 0.161}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 8797726366404580855}
@@ -212,7 +212,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: db8a9548ba56c1949bb28f7c6129bbeb, type: 3}
propertyPath: m_LocalPosition.z
value: 0
value: 0.137
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: db8a9548ba56c1949bb28f7c6129bbeb, type: 3}
propertyPath: m_LocalRotation.w

View File

@@ -48,7 +48,7 @@ MonoBehaviour:
m_Root: {fileID: 8334588817950881727}
m_Mid: {fileID: 5739201115059209923}
m_Tip: {fileID: 1706812538552309319}
m_Target: {fileID: 2781132594439880980}
m_Target: {fileID: 2065766509905691831}
m_Hint: {fileID: 0}
m_TargetPositionWeight: 1
m_TargetRotationWeight: 1
@@ -103,7 +103,7 @@ MonoBehaviour:
m_Root: {fileID: 9127245645273413481}
m_Mid: {fileID: 8862008152122197222}
m_Tip: {fileID: 8703533484509679896}
m_Target: {fileID: 9064841067161443684}
m_Target: {fileID: 909324728237481282}
m_Hint: {fileID: 0}
m_TargetPositionWeight: 1
m_TargetRotationWeight: 1
@@ -606,8 +606,8 @@ MonoBehaviour:
playerController: {fileID: -4574526707603160507}
currentCameraRecoilX: 0
currentCameraRecoilY: 0
gun: {fileID: 3682030003239559187}
gunHolder: {fileID: 7768205653369755348}
gun: {fileID: 3995507965915027724}
gunHolder: {fileID: 8280541971482439080}
positionRecoil: 1
rotationRecoil: 1
positionMultX: 2
@@ -836,7 +836,7 @@ MonoBehaviour:
showGizmos: 0
showOverlay: 0
overlayColor: {r: 0, g: 0, b: 0, a: 0.5}
target: {fileID: 2848367205963120269}
target: {fileID: 1363144486119695814}
--- !u!95 &8957579265169979397
Animator:
serializedVersion: 3
@@ -888,6 +888,7 @@ MonoBehaviour:
syncInterval: 0.1
currentWeaponIndex: 0
activeWeapons: []
gunHolster: {fileID: 6522444664664986769}
cam: {fileID: 6272346181657429395}
--- !u!1 &6272346181657429393
GameObject:
@@ -1233,26 +1234,11 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
--- !u!1 &3682030003239559187 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2213212323547960416, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
m_PrefabInstance: {fileID: 3292089710699836531}
m_PrefabAsset: {fileID: 0}
--- !u!1 &3649358604728444914 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2236875552107647873, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
m_PrefabInstance: {fileID: 3292089710699836531}
m_PrefabAsset: {fileID: 0}
--- !u!4 &2781132594439880980 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 808197646603973991, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
m_PrefabInstance: {fileID: 3292089710699836531}
m_PrefabAsset: {fileID: 0}
--- !u!4 &9064841067161443684 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 5792494204646893847, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
m_PrefabInstance: {fileID: 3292089710699836531}
m_PrefabAsset: {fileID: 0}
--- !u!1 &7768205653369755348 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 5071598280516985511, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
@@ -1469,11 +1455,23 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 1880099159927430553, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5139256649524637864, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalPosition.x
value: -0.008
objectReference: {fileID: 0}
- target: {fileID: 5139256649524637864, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalPosition.y
value: 0.055
objectReference: {fileID: 0}
- target: {fileID: 5139256649524637864, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalPosition.z
value: 0.167
objectReference: {fileID: 0}
- target: {fileID: 7233769674171919731, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalPosition.x
value: 0.0324
value: 0.034
objectReference: {fileID: 0}
- target: {fileID: 7233769674171919731, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalPosition.y
@@ -1483,9 +1481,33 @@ PrefabInstance:
propertyPath: m_LocalPosition.z
value: -0.2867
objectReference: {fileID: 0}
- target: {fileID: 7233769674171919731, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalRotation.w
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7233769674171919731, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7233769674171919731, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalRotation.y
value: 0.7071068
objectReference: {fileID: 0}
- target: {fileID: 7233769674171919731, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalRotation.z
value: 0.7071068
objectReference: {fileID: 0}
- target: {fileID: 7233769674171919731, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: -90
objectReference: {fileID: 0}
- target: {fileID: 7233769674171919731, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 180
objectReference: {fileID: 0}
- target: {fileID: 8382890533894468742, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalPosition.x
value: -0.03000002
value: -0.039
objectReference: {fileID: 0}
- target: {fileID: 8382890533894468742, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalPosition.y
@@ -1495,6 +1517,30 @@ PrefabInstance:
propertyPath: m_LocalPosition.z
value: -0.2881
objectReference: {fileID: 0}
- target: {fileID: 8382890533894468742, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalRotation.w
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8382890533894468742, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8382890533894468742, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalRotation.y
value: 0.7071068
objectReference: {fileID: 0}
- target: {fileID: 8382890533894468742, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalRotation.z
value: 0.7071068
objectReference: {fileID: 0}
- target: {fileID: 8382890533894468742, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: -90
objectReference: {fileID: 0}
- target: {fileID: 8382890533894468742, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 180
objectReference: {fileID: 0}
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_RootOrder
value: 2
@@ -1541,6 +1587,11 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
--- !u!1 &8280541971482439080 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1880099159927430553, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
m_PrefabInstance: {fileID: 7565221866438160433}
m_PrefabAsset: {fileID: 0}
--- !u!4 &1363144486119695814 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
@@ -1551,3 +1602,13 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 6885991082275612989, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
m_PrefabInstance: {fileID: 7565221866438160433}
m_PrefabAsset: {fileID: 0}
--- !u!4 &2065766509905691831 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 8382890533894468742, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
m_PrefabInstance: {fileID: 7565221866438160433}
m_PrefabAsset: {fileID: 0}
--- !u!4 &909324728237481282 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 7233769674171919731, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
m_PrefabInstance: {fileID: 7565221866438160433}
m_PrefabAsset: {fileID: 0}

View File

@@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641258, b: 0.5748172, a: 1}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@@ -258,7 +258,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728911, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
@@ -457,7 +457,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 5204381087217674634, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: weaponKind
value: 1
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
@@ -478,11 +478,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalPosition.x
value: 10.129
value: 10.12892
objectReference: {fileID: 0}
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalPosition.y
value: 0.303
value: 0.30300653
objectReference: {fileID: 0}
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalPosition.z
@@ -490,19 +490,19 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalRotation.w
value: 1
value: 0.9999914
objectReference: {fileID: 0}
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalRotation.x
value: 0
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalRotation.y
value: 0
value: -0
objectReference: {fileID: 0}
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalRotation.z
value: 0
value: 0.0041435333
objectReference: {fileID: 0}
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
@@ -514,7 +514,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 8797726366404580855, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
value: 0.475
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
@@ -1037,6 +1037,27 @@ MeshCollider:
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: -1550514412580984892, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
--- !u!1 &1657029747 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 5071598280516985511, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
m_PrefabInstance: {fileID: 342194877}
m_PrefabAsset: {fileID: 0}
--- !u!54 &1657029752
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1657029747}
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &1683546023 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: -7146521406498821007, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
@@ -1056,6 +1077,27 @@ MeshCollider:
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: -8678823145569952518, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
--- !u!1 &1721250000 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1880099159927430553, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
m_PrefabInstance: {fileID: 409053569}
m_PrefabAsset: {fileID: 0}
--- !u!54 &1721250005
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1721250000}
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &1767188876 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 281855664364225751, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}

View File

@@ -44,7 +44,7 @@ public class Shoot : NetworkBehaviour
totalAmmo = weapon.TotalAmmunition;
updateCanvas = false;
}
if (Input.GetButtonDown("Fire")) {
if (Input.GetButtonDown("Fire")) { // BOX COLLIDER AUS
updateCanvas = true;
Debug.Log(" click");
if (weapon.AllowAction && weapon.CurrentAmmunition > 0)

View File

@@ -7,64 +7,91 @@ using Mirror;
public class WeaponManager : NetworkBehaviour
{
public int currentWeaponIndex = 0;
public GameObject[] activeWeapons;
private int lastWeaponIndex = 0;
private int counter = 0;
public List<GameObject> activeWeapons = new List<GameObject>();
[SerializeField] GameObject gunHolster;
[SerializeField] Camera cam;
private void Awake()
{
activeWeapons = new GameObject[4];
for(int i = 0; i<4; i++)
{
activeWeapons[i] = null;
activeWeapons.Add(null);
}
}
void Update() {
if (isLocalPlayer) {
counter = 0;
if(Input.GetAxis("Mouse ScrollWheel") > 0f){ // Scroll up
do
{
if (currentWeaponIndex <= 0)
{
currentWeaponIndex = activeWeapons.Length - 1;
}
else
{
lastWeaponIndex = currentWeaponIndex;
counter = 0;
do {
if (currentWeaponIndex <= 0) {
currentWeaponIndex = activeWeapons.Count - 1;
} else {
currentWeaponIndex--;
}
counter++;
//Debug.Log(activeWeapons[currentWeaponIndex]);
if (counter > 10) { break; }
} while (activeWeapons[currentWeaponIndex] == null);
if (lastWeaponIndex != currentWeaponIndex && activeWeapons[currentWeaponIndex] != null)
{
// play switch animation or move weapon (hands) down
foreach (GameObject obj in activeWeapons)
{ // Disable all weapons
if (obj != null) { obj.SetActive(false); }
}
Debug.Log("Set Active (" + currentWeaponIndex + "): " + activeWeapons[currentWeaponIndex].name);
activeWeapons[currentWeaponIndex].SetActive(true);
}
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0f){ // Scroll down
do
{
if (currentWeaponIndex >= activeWeapons.Length - 1)
{
lastWeaponIndex = currentWeaponIndex;
counter = 0;
do {
if (currentWeaponIndex >= activeWeapons.Count - 1) {
currentWeaponIndex = 0;
}
else
{
} else {
currentWeaponIndex++;
}
counter++;
//Debug.Log(activeWeapons[currentWeaponIndex]);
if(counter > 10) { break; }
} while (activeWeapons[currentWeaponIndex] == null);
if (lastWeaponIndex != currentWeaponIndex && activeWeapons[currentWeaponIndex] != null)
{
// play switch animation or move weapon (hands) down
foreach (GameObject obj in activeWeapons)
{ // Disable all weapons
if (obj != null) { obj.SetActive(false); }
}
Debug.Log("Set Active (" + currentWeaponIndex + "): " + activeWeapons[currentWeaponIndex].name);
activeWeapons[currentWeaponIndex].SetActive(true);
}
}
if (Input.GetButton("Interact")) // e
if (Input.GetButtonDown("Interact")) // e
{
CmdPickupWeapon();
}else if (Input.GetButton("Drop")) // q Droping weapon
}else if (Input.GetButtonDown("Drop")) // q Droping weapon
{
activeWeapons[currentWeaponIndex] = null;
// WENN GEDROPT WIRD MUSS DIE N<>CHSTE AKTIVE GSUCHT WERDEn
if(activeWeapons[currentWeaponIndex] != null)
{
activeWeapons[currentWeaponIndex].GetComponent<Rigidbody>().useGravity = true;
activeWeapons[currentWeaponIndex].GetComponent<Rigidbody>().isKinematic = false;
activeWeapons[currentWeaponIndex].transform.position = cam.transform.position;
activeWeapons[currentWeaponIndex].GetComponent<BoxCollider>().enabled = true;
activeWeapons[currentWeaponIndex].GetComponent<Rigidbody>().velocity = cam.transform.forward * 10 + cam.transform.up * 2;
activeWeapons[currentWeaponIndex].gameObject.transform.SetParent(null);
activeWeapons[currentWeaponIndex] = null;
}
}
}
}
[Command]
@@ -73,8 +100,16 @@ public class WeaponManager : NetworkBehaviour
{
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
if (obj != null) { obj.SetActive(false); }
}
hit.transform.parent = gunHolster.transform; // Parent weapon to gunHolster
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": activeWeapons[0] = hit.transform.gameObject; break;
case "Pistole": activeWeapons[1] = hit.transform.gameObject; break;