diff --git a/Assets/Inputs/ThirdPersonViewInput.cs b/Assets/Inputs/ThirdPersonViewInput.cs index 89ed85f..751291c 100644 --- a/Assets/Inputs/ThirdPersonViewInput.cs +++ b/Assets/Inputs/ThirdPersonViewInput.cs @@ -139,7 +139,7 @@ public partial class @ThirdPersonViewInput : IInputActionCollection2, IDisposabl }, { ""name"": ""Fire"", - ""type"": ""PassThrough"", + ""type"": ""Button"", ""id"": ""2b493869-f7ab-4acb-8918-11b0265f0993"", ""expectedControlType"": ""Button"", ""processors"": """", @@ -174,7 +174,7 @@ public partial class @ThirdPersonViewInput : IInputActionCollection2, IDisposabl ""name"": """", ""id"": ""5caa47c3-a8d5-4aad-86fe-40cdca87210a"", ""path"": ""/leftButton"", - ""interactions"": ""Hold(duration=0.1)"", + ""interactions"": ""Hold"", ""processors"": """", ""groups"": """", ""action"": ""Fire"", diff --git a/Assets/Inputs/ThirdPersonViewInput.inputactions b/Assets/Inputs/ThirdPersonViewInput.inputactions index a0c0388..2818765 100644 --- a/Assets/Inputs/ThirdPersonViewInput.inputactions +++ b/Assets/Inputs/ThirdPersonViewInput.inputactions @@ -117,7 +117,7 @@ }, { "name": "Fire", - "type": "PassThrough", + "type": "Button", "id": "2b493869-f7ab-4acb-8918-11b0265f0993", "expectedControlType": "Button", "processors": "", @@ -152,7 +152,7 @@ "name": "", "id": "5caa47c3-a8d5-4aad-86fe-40cdca87210a", "path": "/leftButton", - "interactions": "Hold(duration=0.1)", + "interactions": "Hold", "processors": "", "groups": "", "action": "Fire", diff --git a/Assets/Prefabs/BotPrefab/Bot.prefab b/Assets/Prefabs/BotPrefab/Bot.prefab index 4cd3271..87fea76 100644 --- a/Assets/Prefabs/BotPrefab/Bot.prefab +++ b/Assets/Prefabs/BotPrefab/Bot.prefab @@ -151,7 +151,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1105574061174270723} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1.42, z: 1.084} + m_LocalPosition: {x: 0, y: 1.42, z: 1.316} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1740317275426427710} @@ -1125,7 +1125,6 @@ GameObject: - component: {fileID: 1740317275426328325} - component: {fileID: 1740317275426328323} - component: {fileID: 2063326275591512128} - - component: {fileID: 9003219069727127243} - component: {fileID: 3763807728217797723} - component: {fileID: 4342955358919846965} - component: {fileID: 8845315550143730895} @@ -1134,6 +1133,7 @@ GameObject: - component: {fileID: 6609557663758964906} - component: {fileID: 4758249021326882836} - component: {fileID: -190068591826822826} + - component: {fileID: 303563438449043736} m_Layer: 10 m_Name: Bot m_TagString: Untagged @@ -1243,23 +1243,6 @@ MonoBehaviour: isFiring: 0 lookSpeed: 50 fireAnimation: 0 ---- !u!114 &9003219069727127243 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1740317275426328350} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 52f87dd051395614ebf0004d18d43bba, type: 3} - m_Name: - m_EditorClassIdentifier: - raycast: {fileID: 1105574061174270723} - firePoint: {fileID: 8024036354822949060} - projectilePrefab: {fileID: 198792769130808804, guid: 4543ab5e3d405ec40a8d4e9aa5165030, - type: 3} - audioSource: {fileID: 8172543764818839021} --- !u!195 &3763807728217797723 NavMeshAgent: m_ObjectHideFlags: 0 @@ -1479,6 +1462,22 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 +--- !u!114 &303563438449043736 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1740317275426328350} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2a6ce8ea5e584f40922a36bdb4219494, type: 3} + m_Name: + m_EditorClassIdentifier: + raycast: {fileID: 1740317275426328380} + firePoint: {fileID: 1105574061174270723} + projectilePrefab: {fileID: 198792769130808804, guid: 4543ab5e3d405ec40a8d4e9aa5165030, + type: 3} --- !u!1 &1740317275426328352 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/PlayerPrefab/Player.prefab b/Assets/Prefabs/PlayerPrefab/Player.prefab index a6517f9..def41d7 100644 --- a/Assets/Prefabs/PlayerPrefab/Player.prefab +++ b/Assets/Prefabs/PlayerPrefab/Player.prefab @@ -1394,10 +1394,10 @@ GameObject: - component: {fileID: 2528273238195332182} - component: {fileID: 2528273238195332176} - component: {fileID: 2528273238195332168} - - component: {fileID: 5170482295850327424} - component: {fileID: 8568640505362233545} - component: {fileID: 5876264296742387244} - component: {fileID: -7092397416598211530} + - component: {fileID: 1774200722056680610} m_Layer: 10 m_Name: Player m_TagString: Untagged @@ -1439,7 +1439,7 @@ Rigidbody: serializedVersion: 2 m_Mass: 1 m_Drag: 8 - m_AngularDrag: 20 + m_AngularDrag: 0 m_UseGravity: 1 m_IsKinematic: 0 m_Interpolate: 0 @@ -1470,8 +1470,8 @@ Animator: m_Enabled: 1 m_Avatar: {fileID: 9000000, guid: 860793eb3324391468f1c120a75ec049, type: 3} m_Controller: {fileID: 9100000, guid: 3ebf60422b6cb1c498ee4cf238072b43, type: 2} - m_CullingMode: 1 - m_UpdateMode: 0 + m_CullingMode: 0 + m_UpdateMode: 2 m_ApplyRootMotion: 1 m_LinearVelocityBlending: 0 m_WarningMessage: @@ -1531,23 +1531,6 @@ MonoBehaviour: anim: {fileID: 2528273238195332174} canRotate: 1 isCrouching: 0 ---- !u!114 &5170482295850327424 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2528273238195332181} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 52f87dd051395614ebf0004d18d43bba, type: 3} - m_Name: - m_EditorClassIdentifier: - raycast: {fileID: 9178730298827149128} - firePoint: {fileID: 6083229256174510991} - projectilePrefab: {fileID: 198792769130808804, guid: 4543ab5e3d405ec40a8d4e9aa5165030, - type: 3} - audioSource: {fileID: 0} --- !u!114 &8568640505362233545 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1562,10 +1545,9 @@ MonoBehaviour: m_EditorClassIdentifier: targetTransform: {fileID: 2528273238195566709} cameraTransform: {fileID: 3401070369230030472} - lookSpeed: 0.1 + lookSpeed: 0.7 followSpeed: 0.1 pivotSpeed: 0.03 - LookAngle: 0 minimumPivot: -35 maximumPivot: 35 --- !u!114 &5876264296742387244 @@ -1676,6 +1658,21 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 +--- !u!114 &1774200722056680610 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2528273238195332181} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 52f87dd051395614ebf0004d18d43bba, type: 3} + m_Name: + m_EditorClassIdentifier: + firePoint: {fileID: 6083229256174510991} + projectilePrefab: {fileID: 198792769130808804, guid: 4543ab5e3d405ec40a8d4e9aa5165030, + type: 3} --- !u!1 &2528273238195332183 GameObject: m_ObjectHideFlags: 0 @@ -3405,7 +3402,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6083229256174510991} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.373, y: 1.327, z: 1.105} + m_LocalPosition: {x: 0.373, y: 1.327, z: 1.4} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 2528273238195566651} diff --git a/Assets/Scripts/Animators/Leonid Animator/AnimatorHandler.cs b/Assets/Scripts/Animators/Leonid Animator/AnimatorHandler.cs index 5d662ec..9e29308 100644 --- a/Assets/Scripts/Animators/Leonid Animator/AnimatorHandler.cs +++ b/Assets/Scripts/Animators/Leonid Animator/AnimatorHandler.cs @@ -74,8 +74,8 @@ namespace Animators.Leonid_Animator } #endregion - anim.SetFloat(_horizontal, horizontal, 0.1f, Time.deltaTime); - anim.SetFloat(_vertical, vertical, 0.1f, Time.deltaTime); + anim.SetFloat(_horizontal, horizontal, 0.1f, Time.unscaledDeltaTime); + anim.SetFloat(_vertical, vertical, 0.1f, Time.unscaledDeltaTime); if (pressedCrouching == true) { diff --git a/Assets/Scripts/Animators/Leonid Animator/Player/CharacterLocomotion.cs b/Assets/Scripts/Animators/Leonid Animator/Player/CharacterLocomotion.cs index b08d2f7..32a12a4 100644 --- a/Assets/Scripts/Animators/Leonid Animator/Player/CharacterLocomotion.cs +++ b/Assets/Scripts/Animators/Leonid Animator/Player/CharacterLocomotion.cs @@ -1,5 +1,4 @@ -using System; -using UnityEngine; +using UnityEngine; namespace Animators.Leonid_Animator.Player { @@ -40,7 +39,7 @@ namespace Animators.Leonid_Animator.Player private void Update() { - var deltaTime = Time.deltaTime; + var deltaTime = Time.unscaledDeltaTime; _inputHandler.TickInput(deltaTime); _moveDirection = _cameraObject.forward * _inputHandler.vertical + _cameraObject.right * _inputHandler.horizontal; @@ -66,7 +65,7 @@ namespace Animators.Leonid_Animator.Player var velocity = myRigidbody.velocity; myRigidbody.AddForce(_inputHandler.jumpPressed ? new Vector3(0, jumpForce, 0) - : new Vector3(velocity.x*100, -50, velocity.z * 100)); + : new Vector3(velocity.x*200, -50, velocity.z * 200)); } private void LateUpdate() @@ -95,7 +94,6 @@ namespace Animators.Leonid_Animator.Player if (Mathf.Abs(_inputHandler.horizontal) + Mathf.Abs(_inputHandler.vertical) < 0.1) return; - var moveAmount = _inputHandler.moveAmount; var targetDir = _cameraObject.forward * _inputHandler.vertical + _cameraObject.right * _inputHandler.horizontal; targetDir.Normalize(); @@ -103,8 +101,6 @@ namespace Animators.Leonid_Animator.Player if (targetDir == Vector3.zero) targetDir = myTransform.forward; - var rotSpeed = rotationSpeed; - var rotation = Quaternion.LookRotation(targetDir); var targetRotation = Quaternion.Slerp(myTransform.rotation, rotation, rotationSpeed * delta); myTransform.rotation = targetRotation; diff --git a/Assets/Scripts/Animators/Leonid Animator/Player/InputHandler.cs b/Assets/Scripts/Animators/Leonid Animator/Player/InputHandler.cs index 6a2d50c..413b739 100644 --- a/Assets/Scripts/Animators/Leonid Animator/Player/InputHandler.cs +++ b/Assets/Scripts/Animators/Leonid Animator/Player/InputHandler.cs @@ -31,8 +31,8 @@ namespace Animators.Leonid_Animator.Player private void Update() { - _cameraHandler.TargetPosition(Time.deltaTime); - _cameraHandler.HandleCameraRotation(Time.deltaTime, mouseX, mouseY); + _cameraHandler.TargetPosition(Time.unscaledDeltaTime); + _cameraHandler.HandleCameraRotation(Time.unscaledDeltaTime, mouseX, mouseY); } private void OnEnable() @@ -48,7 +48,7 @@ namespace Animators.Leonid_Animator.Player context => crouchPressed = true; _inputActions.PlayerActions.Jump.performed += context => jumpPressed = true; - _inputActions.PlayerActions.Fire.performed += + _inputActions.PlayerActions.Fire.started += context => firePressed = true; _inputActions.PlayerActions.Fire.canceled += context => firePressed = false; diff --git a/Assets/Scripts/Bots/CharacterFactory.cs b/Assets/Scripts/Bots/CharacterFactory.cs index 82c343e..bd2d4f5 100644 --- a/Assets/Scripts/Bots/CharacterFactory.cs +++ b/Assets/Scripts/Bots/CharacterFactory.cs @@ -68,7 +68,9 @@ public class CharacterFactory : MonoBehaviour if (typeAi == TypeAI.HumanAI) { print("added player to list"); - gameobject.GetComponent().GetCharacter.Team = team; + var myPlayer = gameobject.GetComponent().GetCharacter; + myPlayer.Team = team; + myPlayer.TypeAi = TypeAI.HumanAI; Player = gameobject; } else diff --git a/Assets/Scripts/CameraScripts/CameraHandler.cs b/Assets/Scripts/CameraScripts/CameraHandler.cs index 522e5e6..03a7164 100644 --- a/Assets/Scripts/CameraScripts/CameraHandler.cs +++ b/Assets/Scripts/CameraScripts/CameraHandler.cs @@ -1,7 +1,4 @@ -using System; -using Animators.Leonid_Animator; -using Animators.Leonid_Animator.Player; -using Unity.Mathematics; +using Animators.Leonid_Animator; using UnityEngine; namespace CameraScripts @@ -14,11 +11,11 @@ namespace CameraScripts public static CameraHandler Singleton; - [SerializeField] private float lookSpeed = 0.1f; + [SerializeField] private float lookSpeed = 20f; [SerializeField] private float followSpeed = 0.1f; [SerializeField] private float pivotSpeed = 0.03f; - public float LookAngle; + private float _lookAngle; private float _pivotAngle; public float minimumPivot = -35; @@ -48,12 +45,12 @@ namespace CameraScripts public void HandleCameraRotation(float delta, float mouseX, float mouseY) { - LookAngle += (mouseX * lookSpeed) / delta; + _lookAngle += (mouseX * lookSpeed) / delta; _pivotAngle -= (mouseY * pivotSpeed) / delta; _pivotAngle = Mathf.Clamp(_pivotAngle, minimumPivot, maximumPivot); var rotation = Vector3.zero; - rotation.y = LookAngle; + rotation.y = _lookAngle; transform.rotation = Quaternion.Euler(rotation); } } diff --git a/Assets/Scripts/Character/CameraMouseScript.cs b/Assets/Scripts/Character/CameraMouseScript.cs deleted file mode 100644 index b82d9ae..0000000 --- a/Assets/Scripts/Character/CameraMouseScript.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class CameraMouseScript : MonoBehaviour -{ - public float moveSpeed; - public float shiftAdditionalSpeed; - public float mouseSensitivity; - public bool invertMouse; - public bool autoLockCursor; - - public Camera cam; - - public GameObject character; - - void Awake() - { - cam = this.gameObject.GetComponent(); - this.gameObject.name = "SpectatorCamera"; - Cursor.lockState = (autoLockCursor) ? CursorLockMode.Locked : CursorLockMode.None; - } - - void Update () { - if (character.transform.rotation.x < 15 && character.transform.rotation.x > -15) - { - float speed = (moveSpeed + (Input.GetAxis("Fire3") * shiftAdditionalSpeed)); - this.gameObject.transform.Translate(Vector3.forward * speed * Input.GetAxis("Vertical")); - this.gameObject.transform.Translate(Vector3.right * speed * Input.GetAxis("Horizontal")); - this.gameObject.transform.Translate(Vector3.up * speed * - (Input.GetAxis("Jump") + (Input.GetAxis("Fire1") * -1))); - this.gameObject.transform.Rotate(Input.GetAxis("Mouse Y") * mouseSensitivity * ((invertMouse) ? 1 : -1), - Input.GetAxis("Mouse X") * mouseSensitivity * ((invertMouse) ? -1 : 1), 0); - this.gameObject.transform.localEulerAngles = new Vector3(this.gameObject.transform.localEulerAngles.x, - this.gameObject.transform.localEulerAngles.y, 0); - - if (Cursor.lockState == CursorLockMode.None && Input.GetMouseButtonDown(0)) - { - Cursor.lockState = CursorLockMode.Locked; - } - else if (Cursor.lockState == CursorLockMode.Locked && Input.GetKeyDown(KeyCode.Escape)) - { - Cursor.lockState = CursorLockMode.None; - } - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/Character/CameraMouseScript.cs.meta b/Assets/Scripts/Character/CameraMouseScript.cs.meta deleted file mode 100644 index 83957eb..0000000 --- a/Assets/Scripts/Character/CameraMouseScript.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e63e19e155f6b6348897150b67863072 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Character/Player.cs b/Assets/Scripts/Character/Player.cs index 1561b66..892003f 100644 --- a/Assets/Scripts/Character/Player.cs +++ b/Assets/Scripts/Character/Player.cs @@ -26,7 +26,6 @@ public class Player : MonoBehaviour, ICharacter PlayerCharacter.LastTimeHit = TimeManager.Instance.CurrentTime; Condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - Condition.ArmourPoints * 0.5f))); Condition.GiveArmour(-Mathf.RoundToInt(Mathf.Sqrt(damage) * 5)); - print(Condition.HealthPoints); if (Condition.HealthPoints < 10) Die(); } diff --git a/Assets/Scripts/Misc/FlagZone.cs b/Assets/Scripts/Misc/FlagZone.cs index 1e6b817..35cd3ff 100755 --- a/Assets/Scripts/Misc/FlagZone.cs +++ b/Assets/Scripts/Misc/FlagZone.cs @@ -56,7 +56,6 @@ public class FlagZone : MonoBehaviour } else if (occupAttackers > 0) { - print("Atackers ocuppy flag"); TimeStayAttackers += Time.deltaTime; GameManager._attackersTeam.AddGroupReward(Time.deltaTime* 0.1f); GameManager._defendersTeam.AddGroupReward(-Time.deltaTime* 0.1f); @@ -68,7 +67,6 @@ public class FlagZone : MonoBehaviour } else if (occupDefenders > 0) { - print("Defenders ocuppy flag"); GameManager._defendersTeam.AddGroupReward(+Time.deltaTime* 0.1f); TimeStayDefenders += Time.deltaTime; if (TimeStayDefenders > timeForWin) diff --git a/Assets/Scripts/Weapons/AimAssistant.cs b/Assets/Scripts/Weapons/AimAssistant.cs index c640716..2cb23d6 100644 --- a/Assets/Scripts/Weapons/AimAssistant.cs +++ b/Assets/Scripts/Weapons/AimAssistant.cs @@ -1,11 +1,12 @@ using System.Collections; using UnityEngine; +using Weapons; [RequireComponent(typeof(NPC))] public class AimAssistant : MonoBehaviour { [HideInInspector] public GameObject enemy; - private Shooting _shooting; + private BotShooter _botShooter; public bool isFiring = false; private NPC _myNpc; [SerializeField] private float lookSpeed = 400f; @@ -19,14 +20,13 @@ public class AimAssistant : MonoBehaviour private void Awake() { _myNpc = GetComponent(); - _shooting = GetComponent(); + _botShooter = GetComponent(); _myTransform = transform; _fireCountdown = 1f / SettingsReader.Instance.GetSettings.RateOfFire; } private void FixedUpdate() { - //Ищем противника на сцене. if (isFiring == false) { var enemies = GameManager.GetVisibleEnemies(_myNpc.GetCharacter.Team.GetOppositeTeam(), transform.position); @@ -72,6 +72,7 @@ public class AimAssistant : MonoBehaviour if (enemy != null) { var direction = enemy.transform.position - gameObject.transform.position; + if (direction == Vector3.zero) return; var targetRotation = Quaternion.LookRotation(direction); var lookAt = Quaternion.RotateTowards(gameObject.transform.rotation, targetRotation, Time.deltaTime * lookSpeed); @@ -92,8 +93,9 @@ public class AimAssistant : MonoBehaviour { while (true) { - _shooting.BotShoot(); + _botShooter.BotShoot(); yield return new WaitForSeconds(_fireCountdown); } } + } \ No newline at end of file diff --git a/Assets/Scripts/Weapons/BotShooter.cs b/Assets/Scripts/Weapons/BotShooter.cs new file mode 100644 index 0000000..d4611e6 --- /dev/null +++ b/Assets/Scripts/Weapons/BotShooter.cs @@ -0,0 +1,50 @@ +using UnityEngine; + +namespace Weapons +{ + public class BotShooter : MonoBehaviour + { + [SerializeField] private GameObject firePoint; + [SerializeField] private ParticleSystem projectilePrefab; + private NPC _myNpc; + private MovementController _moveCtrl; + private AudioSource _audioSource; + + private void Awake() + { + _myNpc = GetComponent(); + _moveCtrl = GetComponent(); + _audioSource = GetComponent(); + } + + public void BotShoot() + { + if (Physics.Raycast(firePoint.transform.position, + firePoint.transform.forward, out var hit, + SettingsReader.Instance.GetSettings.ViewDistance)) + { + if (hit.transform.TryGetComponent(out var target)) + { + print($"did damage to {hit.transform.name}"); + _audioSource.Play(); + Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation); + var mySpeed = _moveCtrl.Velocity.magnitude; + var enemySpeed = 0f; + var inCover = false; + if (target.GetCharacter.TypeAi == TypeAI.HumanAI) + enemySpeed = hit.rigidbody.velocity.magnitude; + else + { + enemySpeed = hit.collider.GetComponent().Velocity.magnitude; + inCover = hit.collider.GetComponent().NpcState.InCover; + } + + var hitChance = (1 - 0.5 * mySpeed) * (1 - 0.5 * enemySpeed + 0.5*inCover.ToInt()) / 1.5f; + if (!(Random.Range(0f, 1f) < hitChance)) return; + _myNpc.AddReward(0.05f); + target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Weapons/BotShooter.cs.meta b/Assets/Scripts/Weapons/BotShooter.cs.meta new file mode 100644 index 0000000..ea971cc --- /dev/null +++ b/Assets/Scripts/Weapons/BotShooter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2a6ce8ea5e584f40922a36bdb4219494 +timeCreated: 1652982070 \ No newline at end of file diff --git a/Assets/Scripts/Weapons/PlayerShooter.cs b/Assets/Scripts/Weapons/PlayerShooter.cs new file mode 100644 index 0000000..941e1c5 --- /dev/null +++ b/Assets/Scripts/Weapons/PlayerShooter.cs @@ -0,0 +1,57 @@ +using Animators.Leonid_Animator.Player; +using UnityEngine; + +namespace Weapons +{ + [RequireComponent(typeof(AudioSource))] + [RequireComponent(typeof(InputHandler))] + public class PlayerShooter : MonoBehaviour + { + public GameObject firePoint; + + public ParticleSystem projectilePrefab; + + private float _fireCountdown = 0.5f; + + private AudioSource _audioSource; + private InputHandler _inputHandler; + + private void Awake() + { + _audioSource = GetComponent(); + _inputHandler = GetComponent(); + } + + private void Update() + { + HandleMouseButton(); + } + + private void HandleMouseButton() + { + if (_inputHandler.firePressed && _fireCountdown <= 0f) + { + _fireCountdown = 0.5f; + PlayerShoot(); + } + + _fireCountdown -= Time.unscaledDeltaTime; + } + + private void PlayerShoot() + { + _audioSource.Play(); + Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation); + if (Physics.Raycast(firePoint.transform.position, + firePoint.transform.forward, out var hit, + SettingsReader.Instance.GetSettings.ViewDistance)) + { + if (hit.transform.TryGetComponent(out var target)) + { + print($"did damage to {hit.transform.name}"); + target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Weapons/Shooting.cs.meta b/Assets/Scripts/Weapons/PlayerShooter.cs.meta similarity index 100% rename from Assets/Scripts/Weapons/Shooting.cs.meta rename to Assets/Scripts/Weapons/PlayerShooter.cs.meta diff --git a/Assets/Scripts/Weapons/Shooting.cs b/Assets/Scripts/Weapons/Shooting.cs deleted file mode 100644 index 941e3ae..0000000 --- a/Assets/Scripts/Weapons/Shooting.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using JetBrains.Annotations; -using UnityEngine; - -[RequireComponent(typeof(AudioSource))] -public class Shooting : MonoBehaviour -{ - public GameObject raycast; - - public GameObject firePoint; - - public ParticleSystem projectilePrefab; - - private float hSliderValue = 0.1f; - private float _fireCountdown = 0.1f; - - public AudioSource audioSource; - private NPC _myNpc; - private MovementController _moveCtrl; - - private void Awake() - { - audioSource = GetComponent(); - TryGetComponent(out _moveCtrl); - TryGetComponent(out _myNpc); - } - - private void Update() - { - HandleMouseButton(); - } - - private void HandleMouseButton() - { - if (Input.GetMouseButton(0) && _fireCountdown <= 0f) - { - _fireCountdown = 0; - _fireCountdown += hSliderValue; - PlayerShoot(); - } - - _fireCountdown -= Time.deltaTime; - } - - private void PlayerShoot() - { - audioSource.Play(); - Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation); - if (Physics.Raycast(raycast.transform.position, - raycast.transform.forward, out var hit, - SettingsReader.Instance.GetSettings.ViewDistance)) - { - if (hit.transform.TryGetComponent(out var target)) - { - target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage); - } - } - } - - public void BotShoot() - { - if (Physics.Raycast(raycast.transform.position, - raycast.transform.forward, out var hit, - SettingsReader.Instance.GetSettings.ViewDistance)) - { - if (hit.transform.TryGetComponent(out var target)) - { - audioSource.Play(); - Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation); - var mySpeed = _moveCtrl.Velocity.magnitude; - var enemySpeed = 0f; - var inCover = false; - if (target.GetCharacter.TypeAi == TypeAI.HumanAI) - enemySpeed = hit.rigidbody.velocity.magnitude; - else - { - enemySpeed = hit.collider.GetComponent().Velocity.magnitude; - inCover = hit.collider.GetComponent().NpcState.InCover; - } - - var hitChance = (1 - 0.5 * mySpeed) * (1 - 0.5 * enemySpeed + 0.5*inCover.ToInt()) / 1.5f; - if (!(UnityEngine.Random.Range(0f, 1f) < hitChance)) return; - _myNpc.AddReward(0.05f); - target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage); - } - } - } -} \ No newline at end of file diff --git a/Assets/Settings/Game Settings.asset b/Assets/Settings/Game Settings.asset index 5e210e8..9941c85 100644 --- a/Assets/Settings/Game Settings.asset +++ b/Assets/Settings/Game Settings.asset @@ -21,7 +21,7 @@ MonoBehaviour: AtcTeamAI: 3 NumOfDefenders: 3 NumOfAttackers: 3 - HasHumanDefender: 0 + HasHumanDefender: 1 HasHumanAttacker: 0 HealthPickupAmount: 50 ArmourPickupAmount: 50