Make weapon switching work

This commit is contained in:
Sofia 2020-08-20 21:55:11 +03:00
parent 79852b52fb
commit 6c40f7bb6f
5 changed files with 68 additions and 23 deletions

View File

@ -381,7 +381,7 @@ Animator:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6228136265624521654}
m_Enabled: 1
m_Enabled: 0
m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: 8468d9a1f10314a4c998349493611489, type: 2}
m_CullingMode: 0

View File

@ -157,6 +157,36 @@ Transform:
m_Father: {fileID: 4677107243738498813}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &4990576539229878572
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1602672112052966102}
m_Layer: 0
m_Name: ScopeCamera
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1602672112052966102
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4990576539229878572}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 50, y: 50, z: 50}
m_Children: []
m_Father: {fileID: 4677107243738498813}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &5022353220472231776
GameObject:
m_ObjectHideFlags: 0
@ -187,6 +217,7 @@ Transform:
m_Children:
- {fileID: 1605033999665909937}
- {fileID: 264070833573311472}
- {fileID: 1602672112052966102}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -207,7 +238,7 @@ MonoBehaviour:
Handle: {fileID: 1605033999665909937}
LaserPrefab: {fileID: 8009551885746485900, guid: 5c99da0361d098646b319a35fcc80095, type: 3}
RaygunAnimator: {fileID: 823779526010534736}
ScopeCamera: {fileID: 0}
ScopeCamera: {fileID: 1602672112052966102}
BulletSourcePoint: {fileID: 9048980524933835922}
BulletHitLayer:
serializedVersion: 2
@ -309,31 +340,31 @@ PrefabInstance:
m_Modifications:
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalPosition.x
value: 0
value: 0.049091168
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalPosition.y
value: 0
value: 0.063
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalPosition.z
value: 0
value: 0.17629232
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalRotation.x
value: -0.5
value: -0.5604943
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalRotation.y
value: -0.5
value: -0.3032949
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalRotation.z
value: -0.5
value: -0.43109903
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalRotation.w
value: 0.5
value: 0.63875824
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_RootOrder
@ -341,11 +372,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: -90
value: -77.834
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
value: 27.035
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalEulerAnglesHint.z

View File

@ -32,7 +32,7 @@ TextureImporter:
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
filterMode: 0
aniso: -1
mipBias: -100
wrapU: 1

View File

@ -1,7 +1,7 @@
using UnityEngine;
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using NeonTea.Quakeball.Interface;
using NeonTea.Quakeball.Networking;
using NeonTea.Quakeball.Networking.Packets;
namespace NeonTea.Quakeball.Players {
@ -20,6 +20,8 @@ namespace NeonTea.Quakeball.Players {
private InputAction ShootAction;
private InputAction SwitchUpAction;
private InputAction[] WeaponSwitchActions = new InputAction[9];
private float PreviousPlayerUpdate = -1;
private float PreviousPlayerFullSync = -1;
private bool WantsToJump = false;
@ -53,15 +55,17 @@ namespace NeonTea.Quakeball.Players {
Networking.Net.Singleton.Instance.LocalPlayerAction(PlayerAction.Shoot, shootData);
}
Player.Shoot();
};/*
ShootAction = new InputAction("Shoot", binding: "<Mouse>/leftButton");
ShootAction.performed += _ => {
if (Networking.Net.Singleton.Instance != null) {
ShootData shootData = new ShootData(Player.Pitch, Player.Yaw, Player.CreateSyncPacket());
Networking.Net.Singleton.Instance.LocalPlayerAction(PlayerAction.Shoot, shootData);
}
Player.Shoot();
};*/
};
Action<InputAction.CallbackContext> CreateLambda(int number) {
return (context) => {
Player.SwitchItem(number);
Player.CurrentItem.Animator.enabled = true;
};
}
for (int i = 0; i < 9; i++) {
WeaponSwitchActions[i] = new InputAction($"Switch to weapon {i + 1}", binding: $"<Keyboard>/{i + 1}");
WeaponSwitchActions[i].performed += CreateLambda(i);
}
Terminal.Singleton.RegisterCommand("tp", args => {
if (args.Length != 3) {
@ -79,6 +83,9 @@ namespace NeonTea.Quakeball.Players {
LookAction.Disable();
MoveAction.Disable();
ShootAction.Disable();
foreach (InputAction action in WeaponSwitchActions) {
action.Disable();
}
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
} else {
@ -87,6 +94,9 @@ namespace NeonTea.Quakeball.Players {
LookAction.Enable();
MoveAction.Enable();
ShootAction.Enable();
foreach (InputAction action in WeaponSwitchActions) {
action.Enable();
}
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}

View File

@ -224,9 +224,13 @@ namespace NeonTea.Quakeball.Players {
CurrentItem.SwitchedOut();
}
GameObject obj = GameObject.Instantiate(PossibleItems[index]);
Vector3 localPos = obj.transform.localPosition;
Quaternion localRot = obj.transform.localRotation;
obj.transform.parent = ItemRoot.transform;
obj.transform.localPosition = localPos;
obj.transform.localRotation = localRot;
CurrentItem = obj.GetComponent<Item>();
CurrentItem.Holder = this;
CurrentItem.Switched();