mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
Weapon Switching/Pickup/Throwing
+ weapon switching works + weapon pickup works + weapon throwing works ntba weapon in correct position ntba weapon switch/pickup/throw animation
This commit is contained in:
@@ -1455,7 +1455,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 1880099159927430553, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
|
- target: {fileID: 1880099159927430553, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
|
||||||
propertyPath: m_IsActive
|
propertyPath: m_IsActive
|
||||||
value: 1
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 5139256649524637864, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
|
- target: {fileID: 5139256649524637864, guid: 6f5ccb6e55f1676429c170257dc7a411, type: 3}
|
||||||
propertyPath: m_LocalPosition.x
|
propertyPath: m_LocalPosition.x
|
||||||
|
|||||||
@@ -110,12 +110,12 @@ public class ProcedualAnimationController : NetworkBehaviour
|
|||||||
{
|
{
|
||||||
if (isLocalPlayer)
|
if (isLocalPlayer)
|
||||||
{
|
{
|
||||||
//Play the animation
|
//Play the animation
|
||||||
gunAnimator.Play("Shoot");
|
gunAnimator.Play("Shoot");
|
||||||
//Add force for the recoil
|
//Add force for the recoil
|
||||||
//currentCameraRecoilX -= weightedPerlinNoise(cameraRecoilX, 1f, Time.time, 1);
|
//currentCameraRecoilX -= weightedPerlinNoise(cameraRecoilX, 1f, Time.time, 1);
|
||||||
//playerMouseLook = Mathf.SmoothDamp(playerMouseLook.fullPitch, playerMouseLook.fullPitch - weightedPerlinNoise(cameraRecoilX, 1f, Time.time, 1),ref f,0.01f);
|
//playerMouseLook = Mathf.SmoothDamp(playerMouseLook.fullPitch, playerMouseLook.fullPitch - weightedPerlinNoise(cameraRecoilX, 1f, Time.time, 1),ref f,0.01f);
|
||||||
CmdRecoil();
|
CmdRecoil();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[Command]
|
[Command]
|
||||||
|
|||||||
@@ -44,9 +44,12 @@ public class Shoot : NetworkBehaviour
|
|||||||
totalAmmo = weapon.TotalAmmunition;
|
totalAmmo = weapon.TotalAmmunition;
|
||||||
updateCanvas = false;
|
updateCanvas = false;
|
||||||
}
|
}
|
||||||
if (Input.GetButtonDown("Fire")) { // BOX COLLIDER AUS
|
if (Input.GetButtonDown("Fire")) {
|
||||||
updateCanvas = true;
|
updateCanvas = true;
|
||||||
Debug.Log(" click");
|
if(weapon.GetComponent<BoxCollider>().enabled == true) // NACH ANDERE L<>SUNG SUCHEN
|
||||||
|
{
|
||||||
|
weapon.GetComponent<BoxCollider>().enabled = false;
|
||||||
|
}
|
||||||
if (weapon.AllowAction && weapon.CurrentAmmunition > 0)
|
if (weapon.AllowAction && weapon.CurrentAmmunition > 0)
|
||||||
{
|
{
|
||||||
shootAnim.Recoil(0.1f);
|
shootAnim.Recoil(0.1f);
|
||||||
@@ -97,7 +100,7 @@ public class Shoot : NetworkBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bulletHole(GameObject holeObject, RaycastHit hit)
|
void bulletHole(GameObject holeObject, RaycastHit hit) // Nur zum testen da
|
||||||
{
|
{
|
||||||
holeObject.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
|
holeObject.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
|
||||||
holeObject.transform.position = hit.point;
|
holeObject.transform.position = hit.point;
|
||||||
|
|||||||
@@ -27,48 +27,20 @@ public class WeaponManager : NetworkBehaviour
|
|||||||
if (isLocalPlayer) {
|
if (isLocalPlayer) {
|
||||||
if(Input.GetAxis("Mouse ScrollWheel") > 0f){ // Scroll up
|
if(Input.GetAxis("Mouse ScrollWheel") > 0f){ // Scroll up
|
||||||
lastWeaponIndex = currentWeaponIndex;
|
lastWeaponIndex = currentWeaponIndex;
|
||||||
counter = 0;
|
int nextActive = SearchForNext(activeWeapons, lastWeaponIndex, -1);
|
||||||
do {
|
if (nextActive != -1) { // -1 no next found
|
||||||
if (currentWeaponIndex <= 0) {
|
currentWeaponIndex = nextActive;
|
||||||
currentWeaponIndex = activeWeapons.Count - 1;
|
|
||||||
} else {
|
|
||||||
currentWeaponIndex--;
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
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);
|
activeWeapons[currentWeaponIndex].SetActive(true);
|
||||||
|
// play weapon switch animation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Input.GetAxis("Mouse ScrollWheel") < 0f){ // Scroll down
|
else if (Input.GetAxis("Mouse ScrollWheel") < 0f){ // Scroll down
|
||||||
lastWeaponIndex = currentWeaponIndex;
|
lastWeaponIndex = currentWeaponIndex;
|
||||||
counter = 0;
|
int nextActive = SearchForNext(activeWeapons, lastWeaponIndex, 1);
|
||||||
do {
|
if (nextActive != -1) { // -1 no next found
|
||||||
if (currentWeaponIndex >= activeWeapons.Count - 1) {
|
currentWeaponIndex = nextActive;
|
||||||
currentWeaponIndex = 0;
|
|
||||||
} else {
|
|
||||||
currentWeaponIndex++;
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
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);
|
activeWeapons[currentWeaponIndex].SetActive(true);
|
||||||
|
// play weapon switch animation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,22 +50,56 @@ public class WeaponManager : NetworkBehaviour
|
|||||||
|
|
||||||
}else if (Input.GetButtonDown("Drop")) // q Droping weapon
|
}else if (Input.GetButtonDown("Drop")) // q Droping weapon
|
||||||
{
|
{
|
||||||
// WENN GEDROPT WIRD MUSS DIE N<>CHSTE AKTIVE GSUCHT WERDEn
|
|
||||||
if(activeWeapons[currentWeaponIndex] != null)
|
if(activeWeapons[currentWeaponIndex] != null)
|
||||||
{
|
{
|
||||||
activeWeapons[currentWeaponIndex].GetComponent<Rigidbody>().useGravity = true;
|
Rigidbody rigid = activeWeapons[currentWeaponIndex].GetComponent<Rigidbody>();
|
||||||
activeWeapons[currentWeaponIndex].GetComponent<Rigidbody>().isKinematic = false;
|
rigid.useGravity = true;
|
||||||
|
rigid.isKinematic = false;
|
||||||
activeWeapons[currentWeaponIndex].transform.position = cam.transform.position;
|
activeWeapons[currentWeaponIndex].transform.position = cam.transform.position;
|
||||||
activeWeapons[currentWeaponIndex].GetComponent<BoxCollider>().enabled = true;
|
activeWeapons[currentWeaponIndex].GetComponent<BoxCollider>().enabled = true;
|
||||||
activeWeapons[currentWeaponIndex].GetComponent<Rigidbody>().velocity = cam.transform.forward * 10 + cam.transform.up * 2;
|
rigid.velocity = cam.transform.forward * 10 + cam.transform.up * 2;
|
||||||
activeWeapons[currentWeaponIndex].gameObject.transform.SetParent(null);
|
activeWeapons[currentWeaponIndex].gameObject.transform.SetParent(null);
|
||||||
activeWeapons[currentWeaponIndex] = null;
|
activeWeapons[currentWeaponIndex] = null;
|
||||||
|
|
||||||
|
int nextActive = SearchForNext(activeWeapons, currentWeaponIndex, 1);
|
||||||
|
if(nextActive != -1) // -1 no next found
|
||||||
|
{
|
||||||
|
lastWeaponIndex = currentWeaponIndex;
|
||||||
|
currentWeaponIndex = nextActive;
|
||||||
|
activeWeapons[currentWeaponIndex].SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int SearchForNext(List<GameObject> l, int lastActive = 0, int direction = 1) {
|
||||||
|
int size = l.Count-1;
|
||||||
|
bool condition = true;
|
||||||
|
if (lastActive <= -1) { lastActive = size; }
|
||||||
|
if(lastActive >= l.Count) { lastActive = 0; }
|
||||||
|
for (int i = lastActive+direction; condition; i+= direction) {
|
||||||
|
if (i >= l.Count-1) { i = 0; size = lastActive+1; }
|
||||||
|
else if(i < 0) { i = size; size = -1; }
|
||||||
|
if (l[i] != null) {
|
||||||
|
if(l[lastActive] != null) { l[lastActive].SetActive(false); }
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
if (direction == 1) {
|
||||||
|
if (i < size + 1) { condition = true; }
|
||||||
|
else { condition = false; }
|
||||||
|
}else if(direction == -1) {
|
||||||
|
if (i > size + 1) { condition = true; }
|
||||||
|
else { condition = false; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
private void CmdPickupWeapon() {
|
private void CmdPickupWeapon() {
|
||||||
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit hit))
|
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit hit))
|
||||||
|
|||||||
Reference in New Issue
Block a user