diff --git a/Assets/Scripts/Characters/Enemy/EnemyController.cs b/Assets/Scripts/Characters/Enemy/EnemyController.cs index da9f404..22f9eb5 100644 --- a/Assets/Scripts/Characters/Enemy/EnemyController.cs +++ b/Assets/Scripts/Characters/Enemy/EnemyController.cs @@ -49,6 +49,7 @@ public partial class EnemyController : Pawn public NavMeshPath navMeshPath; public bool isKilling = false; [SerializeField] private bool canAttack = true; + void Start() { // Time.timeScale = 10; @@ -93,6 +94,11 @@ public partial class EnemyController : Pawn _remainingDistance = controller.GetPathRemainingDistance(); hasPath = controller.pathStatus != NavMeshPathStatus.PathComplete; + // if (controller.pathStatus == NavMeshPathStatus.PathComplete && !controller.pathPending && _target != null) + // { + // _target = null; + // } + // Есть таргет? if (_target != null) // Да { @@ -100,19 +106,13 @@ public partial class EnemyController : Pawn float distance = Vector3.Distance(_target.transform.position, transform.position); - if (distance < aggressionDistance) // (_remainingDistance < aggressionDistance && _remainingDistance > 0) + if (distance < aggressionDistance) { aimTarget.position = _target.position + _target.up * 1.2f; targetLayerWeight = 1f; - - // Debug.Log(_remainingDistance); - - // Если подошли к нему + if (distance < 1f) { - // Debug.Log("da"); - - // _target.GetComponent().DropProp(); if (canAttack && !isKilling) { RpcKillPlayer(_target); @@ -129,15 +129,12 @@ public partial class EnemyController : Pawn } else { - //if (controller.GetPathRemainingDistance() <= 0f) // Нет mojet doiti targetLayerWeight = 0f; // Ищем ближайшего игрока foreach (var player in players) { float distance = Vector3.Distance(player.transform.position, transform.position); - // Debug.Log(CalculateNewPath(player.transform)); - if (distance <= aggressionDistance && CalculateNewPath(player.transform)) // && _remainingDistance > 0 { //if (_remainingDistance < aggressionDistance && controller.GetPathRemainingDistance() >= 0) diff --git a/Assets/Scripts/Characters/PersonController/Interactions.cs b/Assets/Scripts/Characters/PersonController/Interactions.cs index 79a6b93..7435ec3 100644 --- a/Assets/Scripts/Characters/PersonController/Interactions.cs +++ b/Assets/Scripts/Characters/PersonController/Interactions.cs @@ -183,18 +183,24 @@ public class Interactions : NetworkBehaviour if (hitInfo.transform != null) { - // var player = hitInfo.transform.gameObject.GetComponent(); - var player = hitInfo.transform.gameObject.GetComponent(); - if (player != null) + var pawn = hitInfo.transform.gameObject.GetComponent(); + + if (pawn != null) { - CmdReductStamina(player); - CmdAddDebuff(player); - } - var alien = hitInfo.transform.gameObject.GetComponent(); - if (alien != null) - { - CmdHitAlien(alien); + CmdHitPawn(pawn); } + // + // var player = hitInfo.transform.gameObject.GetComponent(); + // if (player != null) + // { + // CmdReductStamina(player); + // CmdAddDebuff(player); + // } + // var alien = hitInfo.transform.gameObject.GetComponent(); + // if (alien != null) + // { + // CmdHitAlien(alien); + // } } CmdShoot(hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); @@ -213,28 +219,15 @@ public class Interactions : NetworkBehaviour } [Command(requiresAuthority = false)] - void CmdReductStamina(PersonController player) + void CmdHitPawn(Pawn pawn) { - RpcReductStamina(player); + RpcHitPawn(pawn); } [ClientRpc] - void RpcReductStamina(PersonController player) + void RpcHitPawn(Pawn pawn) { - player.TakeDamage(); - player.InstantStaminaReduction(controller.shootDepletion * 0.7f); - } - - [Command] - void CmdHitAlien(EnemyController alien) - { - RpcHitAlien(alien); - } - - [ClientRpc] - void RpcHitAlien(EnemyController alien) - { - alien.TakeDamage(); + pawn.TakeDamage(); } [Command] diff --git a/Assets/Scripts/Characters/PersonController/Interactions2.cs b/Assets/Scripts/Characters/PersonController/Interactions2.cs deleted file mode 100644 index 183b532..0000000 --- a/Assets/Scripts/Characters/PersonController/Interactions2.cs +++ /dev/null @@ -1,157 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using Mirror; -using UnityEngine.Animations.Rigging; - -public class Interactions2 : NetworkBehaviour -{ - [Header("Animations")] - [SyncVar] - private float takePropWeight = 0f; - public Rig takePropRig; - public Transform leftHandPos, rightHandPos; - public GameObject _eyesObject; - - [Header("Prop Prefs")] - public GameObject propPrefab; - private RaycastHit _hit; - private Rigidbody _propRB; - - [Header("Settings")] - public float maxHitDistance = 6f; - - [Header("GUI Staff")] - public float hitDistance; - public bool canInterract; - - [Header("Links")] - public StarterAssets.PersonController controller; - - private PropGrab _grabbedProp; - - void Update() - { - takePropRig.weight = takePropWeight; - - if (!isLocalPlayer) return; - - if (Physics.Raycast(_eyesObject.transform.position, _eyesObject.transform.TransformDirection(Vector3.forward), out _hit, maxHitDistance, LayerMask.NameToLayer("Player"))) - { - Debug.DrawRay(_eyesObject.transform.position, _eyesObject.transform.TransformDirection(Vector3.forward) * hitDistance, Color.yellow); - - canInterract = _hit.collider.tag == "Prop" || _hit.collider.tag == "Button" ? true : false; - - if (Input.GetKey(KeyCode.E)) - { - if (_hit.collider.tag == "Prop" && _propRB == null) - { - _propRB = _hit.collider.gameObject.GetComponent(); - } - } - } - - hitDistance = _hit.distance > 0 ? _hit.distance : maxHitDistance; - - if (Input.GetKey(KeyCode.E)) - { - if (_propRB != null) - { - Vector3 target = _eyesObject.transform.position + _eyesObject.transform.forward; - - if (isClient) - { - CmdPropGrab(target, _propRB.gameObject, _eyesObject.transform.rotation); - SetPropRigWeight(1f); - - CmdSetLayerMask(_propRB.gameObject, "Grab"); - } - - PropBehaviour propBehaviour = _propRB.GetComponent(); - setHands(leftHandPos, rightHandPos, propBehaviour); - } - } - else - { - if (isClient) - { - if (_propRB != null) - { - CmdSetLayerMask(_propRB.gameObject, "Default"); - } - - SetPropRigWeight(0f); - } - _propRB = null; - } - - if (Input.GetKeyDown(KeyCode.Q)) - { - if (isClient) - { - CmdSpawnObject(_eyesObject.transform.position + _eyesObject.transform.forward, _eyesObject.transform.rotation); - } - } - } - - #region Commands - [Command] - void CmdPropGrab(Vector3 target, GameObject prop, Quaternion dir) - { - RpcPropGrab(target, prop, dir); - } - - [Command] - void CmdSetLayerMask(GameObject gameObject, string str) - { - RpcSetLayerMask(gameObject, str); - } - - [Command] - void SetPropRigWeight(float value) - { - takePropWeight = value; - } - - [Command] - void CmdSpawnObject(Vector3 pos, Quaternion rot) - { - GameObject gameObject = Instantiate(propPrefab, pos, rot); - NetworkServer.Spawn(gameObject); - } - #endregion - - #region Rpcs - [ClientRpc] - void RpcSetLayerMask(GameObject gameObject, string str) - { - gameObject.layer = LayerMask.NameToLayer(str); - } - - [ClientRpc] - void RpcPropGrab(Vector3 target, GameObject prop, Quaternion dir) - { - Rigidbody propRB = prop.GetComponent(); - - Vector3 tarForce = target - propRB.transform.position; - Vector3 force = (tarForce * 20f - propRB.velocity) * Time.deltaTime * 30f; - - propRB.AddForce(force, ForceMode.Impulse); - - propRB.MoveRotation(dir); - } - - #endregion - - #region Methods - - void setHands(Transform lh, Transform rh, PropBehaviour pb) - { - lh.position = pb.leftHandPos.position; - rh.position = pb.rightHandPos.position; - - lh.rotation = pb.leftHandPos.rotation; - rh.rotation = pb.rightHandPos.rotation; - } - #endregion -} diff --git a/Assets/Scripts/Characters/PersonController/Interactions2.cs.meta b/Assets/Scripts/Characters/PersonController/Interactions2.cs.meta deleted file mode 100644 index 1b6fa93..0000000 --- a/Assets/Scripts/Characters/PersonController/Interactions2.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 2d857e8e2df2a1143ab80b10cbb93b9c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Characters/PersonController/PersonController.cs b/Assets/Scripts/Characters/PersonController/PersonController.cs index 4091c04..34527ee 100644 --- a/Assets/Scripts/Characters/PersonController/PersonController.cs +++ b/Assets/Scripts/Characters/PersonController/PersonController.cs @@ -122,7 +122,7 @@ namespace StarterAssets private void Start() { _controller = GetComponent(); - this.OnDamage += TakeDamageAnimation; + this.OnDamage += OnTakeDamage; _gotEnergyClip = Resources.Load("Audio/CharacterSounds/GetEnergy"); @@ -348,9 +348,11 @@ namespace StarterAssets _parent = transf; } - void TakeDamageAnimation(Pawn self) + // server + void OnTakeDamage(Pawn self) { _animator.SetTrigger("damage"); + InstantStaminaReduction(shootDepletion * 0.7f); // Debug.Log(self.GetComponent().playerName); // hitVFX.Stop();