SearchForNext Overhaul

This commit is contained in:
juliuse98
2021-11-29 12:21:32 +01:00
parent 59ff72d498
commit cf5d47eca9
4 changed files with 37 additions and 11 deletions

View File

@@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_IndirectSpecularColor: {r: 0.44657826, g: 0.49641263, b: 0.57481676, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@@ -2375,7 +2375,7 @@ PrefabInstance:
- target: {fileID: 5784756223373504909, guid: 5cd2e2b44dc49ae44b48fc76a1e09712, type: 3}
propertyPath: playerPrefab
value:
objectReference: {fileID: 6272346181302961293, guid: 2935eead9a075fd489d6a6dc273a5999, type: 3}
objectReference: {fileID: 6272346181302961293, guid: a14d876ac00bdf6498e30b3e58b68fdf, type: 3}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 5cd2e2b44dc49ae44b48fc76a1e09712, type: 3}
--- !u!1001 &3454029965885532949

View File

@@ -124,8 +124,6 @@ public class PlayerController : NetworkBehaviour
if(isGrounded && velocity.y < -fallDamageSpeed)
{
Debug.Log(velocity.y);
Debug.Log("Fall Damage");
CmdFallDamage((int)Mathf.Abs(velocity.y));
}

View File

@@ -27,13 +27,15 @@ public class WeaponManager : NetworkBehaviour
if (isLocalPlayer) {
if (Input.GetAxis("Mouse ScrollWheel") > 0f) { // Scroll up
lastWeaponIndex = currentWeaponIndex;
activeWeapons[currentWeaponIndex].SetActive(false);
switchWeapon(-1);
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0f) { // Scroll down
lastWeaponIndex = currentWeaponIndex;
activeWeapons[currentWeaponIndex].SetActive(false);
switchWeapon(1);
}
activeWeapons[currentWeaponIndex].SetActive(true);
if (Input.GetButtonDown("Interact")) { // e
PickupWeapon();
@@ -41,6 +43,7 @@ public class WeaponManager : NetworkBehaviour
if (activeWeapons[currentWeaponIndex] != null) {
dropWeapon(); // Throws weapon away
switchWeapon(1);
activeWeapons[currentWeaponIndex].SetActive(true);
}
}
}
@@ -48,21 +51,46 @@ public class WeaponManager : NetworkBehaviour
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) {
private int searchForNext(List<GameObject> l, int lastActive = 0, int direction = 1)
{
int current = lastActive + direction;
for (int trys = 0; trys < l.Count; trys++)
{
//Check if you are at the start or end of the list and loop around accordingly
if (current < 0) current = l.Count - 1;
else if (current >= l.Count) current = 0;
//Check if in the current position is a gun or not
if (l[current] != null)
{
return current;
}
//if there is no gun go to the next
current = current + direction;
}
//If no next gun can be found return the index of the gun that was already selected
return lastActive;
}
private int searchForNextOld(List<GameObject> l, int lastActive = 0, int direction = 1) {
int size = l.Count;
bool condition = true;
int counter = 0;

View File

@@ -1,2 +1,2 @@
m_EditorVersion: 2021.2.0f1
m_EditorVersionWithRevision: 2021.2.0f1 (4bf1ec4b23c9)
m_EditorVersion: 2021.2.3f1
m_EditorVersionWithRevision: 2021.2.3f1 (32358a8527b4)