remade combo
This commit is contained in:
parent
30af4cf09a
commit
a9d13807df
@ -316,8 +316,9 @@ GameObject:
|
||||
- component: {fileID: 298037255}
|
||||
- component: {fileID: 298037254}
|
||||
- component: {fileID: 298037253}
|
||||
- component: {fileID: 298037256}
|
||||
m_Layer: 6
|
||||
m_Name: Enemy
|
||||
m_Name: Boxsack
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@ -378,6 +379,18 @@ Transform:
|
||||
- {fileID: 1999379258}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &298037256
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 298037252}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d1940334a0376f544a48be3462f080cf, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &298108316
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -1214,6 +1227,7 @@ GameObject:
|
||||
- component: {fileID: 820174472}
|
||||
- component: {fileID: 820174473}
|
||||
- component: {fileID: 820174475}
|
||||
- component: {fileID: 820174476}
|
||||
m_Layer: 6
|
||||
m_Name: Enemy
|
||||
m_TagString: Untagged
|
||||
@ -1236,6 +1250,7 @@ Transform:
|
||||
m_Children:
|
||||
- {fileID: 1884508223}
|
||||
- {fileID: 1847948565}
|
||||
- {fileID: 1463209973}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!195 &820174472
|
||||
@ -1310,8 +1325,20 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
initHealth: 100
|
||||
canvas: {fileID: 0}
|
||||
damagePrefab: {fileID: 0}
|
||||
canvas: {fileID: 1463209969}
|
||||
damagePrefab: {fileID: 3181908850916544684, guid: 174e0d007c667514aae5c50223ecec58, type: 3}
|
||||
--- !u!114 &820174476
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 820174469}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 54c8ceddec4e45a4299dad732c0f50a8, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &832575517
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -1669,6 +1696,107 @@ Transform:
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1091178979}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1463209969
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1463209973}
|
||||
- component: {fileID: 1463209972}
|
||||
- component: {fileID: 1463209971}
|
||||
- component: {fileID: 1463209970}
|
||||
m_Layer: 6
|
||||
m_Name: Canvas
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1463209970
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1463209969}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_IgnoreReversedGraphics: 1
|
||||
m_BlockingObjects: 0
|
||||
m_BlockingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
--- !u!114 &1463209971
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1463209969}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_UiScaleMode: 0
|
||||
m_ReferencePixelsPerUnit: 100
|
||||
m_ScaleFactor: 1
|
||||
m_ReferenceResolution: {x: 800, y: 600}
|
||||
m_ScreenMatchMode: 0
|
||||
m_MatchWidthOrHeight: 0
|
||||
m_PhysicalUnit: 3
|
||||
m_FallbackScreenDPI: 96
|
||||
m_DefaultSpriteDPI: 96
|
||||
m_DynamicPixelsPerUnit: 1
|
||||
m_PresetInfoIsWorld: 1
|
||||
--- !u!223 &1463209972
|
||||
Canvas:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1463209969}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_RenderMode: 2
|
||||
m_Camera: {fileID: 0}
|
||||
m_PlaneDistance: 100
|
||||
m_PixelPerfect: 0
|
||||
m_ReceivesEvents: 1
|
||||
m_OverrideSorting: 0
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_VertexColorAlwaysGammaSpace: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_UpdateRectTransformForStandalone: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 0
|
||||
m_TargetDisplay: 0
|
||||
--- !u!224 &1463209973
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1463209969}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
|
||||
m_ConstrainProportionsScale: 1
|
||||
m_Children: []
|
||||
m_Father: {fileID: 820174471}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 2, y: 1}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!1 &1483870827 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: a0b56cb96370346c29fa346cedbbc0f4, type: 3}
|
||||
@ -2367,8 +2495,7 @@ GameObject:
|
||||
- component: {fileID: 1884508223}
|
||||
- component: {fileID: 1884508226}
|
||||
- component: {fileID: 1884508225}
|
||||
- component: {fileID: 1884508224}
|
||||
m_Layer: 3
|
||||
m_Layer: 6
|
||||
m_Name: Cube (1)
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
@ -2390,27 +2517,6 @@ Transform:
|
||||
m_Children: []
|
||||
m_Father: {fileID: 820174471}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!65 &1884508224
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1884508222}
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_LayerOverridePriority: 0
|
||||
m_IsTrigger: 0
|
||||
m_ProvidesContacts: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Size: {x: 1, y: 1, z: 1}
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!23 &1884508225
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -2704,7 +2810,6 @@ MonoBehaviour:
|
||||
minAimDistance: 25
|
||||
maxAimDistance: 20
|
||||
aimCanvas: {fileID: 1965505415}
|
||||
detectionAngle: 7.5
|
||||
dashSpeed: 36
|
||||
dashTime: 0.2
|
||||
dashCooldownTime: 1
|
||||
|
@ -1,63 +1,66 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class Animate : MonoBehaviour
|
||||
namespace Creatures
|
||||
{
|
||||
private Animator _animator;
|
||||
private RuntimeAnimatorController _animatorController;
|
||||
public void initialize(Animator animator)
|
||||
public class Animate : MonoBehaviour
|
||||
{
|
||||
_animator = animator;
|
||||
_animatorController = animator.runtimeAnimatorController;
|
||||
}
|
||||
private Animator _animator;
|
||||
private RuntimeAnimatorController _animatorController;
|
||||
public void initialize(Animator animator)
|
||||
{
|
||||
_animator = animator;
|
||||
_animatorController = animator.runtimeAnimatorController;
|
||||
}
|
||||
|
||||
public void AnimateState(string animVar, float animVal, float animationSpeed)
|
||||
{
|
||||
float t = Mathf.Clamp01(animationSpeed*Time.deltaTime);
|
||||
float newVal = Mathf.Lerp(_animator.GetFloat(animVar), animVal, t);
|
||||
_animator.SetFloat(animVar, newVal);
|
||||
public void AnimateState(string animVar, float animVal, float animationSpeed)
|
||||
{
|
||||
float t = Mathf.Clamp01(animationSpeed*Time.deltaTime);
|
||||
float newVal = Mathf.Lerp(_animator.GetFloat(animVar), animVal, t);
|
||||
_animator.SetFloat(animVar, newVal);
|
||||
|
||||
//animator.Play("Attack");
|
||||
//print(animator.GetCurrentAnimatorStateInfo(1).IsName("Idle"));
|
||||
}
|
||||
//animator.Play("Attack");
|
||||
//print(animator.GetCurrentAnimatorStateInfo(1).IsName("Idle"));
|
||||
}
|
||||
|
||||
public bool IsCurrentAnimation(string name)
|
||||
{
|
||||
return _animator.GetCurrentAnimatorStateInfo(0).IsName(name);
|
||||
}
|
||||
public bool IsCurrentAnimation(string name)
|
||||
{
|
||||
return _animator.GetCurrentAnimatorStateInfo(0).IsName(name);
|
||||
}
|
||||
|
||||
public void TriggerAnimation(string triggerName)
|
||||
{
|
||||
_animator.SetTrigger(triggerName);
|
||||
}
|
||||
public void TriggerAnimation(string triggerName)
|
||||
{
|
||||
_animator.SetTrigger(triggerName);
|
||||
}
|
||||
|
||||
public event Action OnStartDamage;
|
||||
public event Action OnEndDamage;
|
||||
public event Action OnReset;
|
||||
public event Action OnAnimationEnd;
|
||||
void LeftReset(AnimationEvent animationEvent)
|
||||
{
|
||||
OnReset?.Invoke();
|
||||
}
|
||||
void RightReset(AnimationEvent animationEvent)
|
||||
{
|
||||
OnReset?.Invoke();
|
||||
}
|
||||
void KickReset(AnimationEvent animationEvent)
|
||||
{
|
||||
OnReset?.Invoke();
|
||||
}
|
||||
void StartDamage(AnimationEvent animationEvent)
|
||||
{
|
||||
OnStartDamage?.Invoke();
|
||||
}
|
||||
void EndDamage(AnimationEvent animationEvent)
|
||||
{
|
||||
OnEndDamage?.Invoke();
|
||||
}
|
||||
public event Action OnStartDamage;
|
||||
public event Action OnEndDamage;
|
||||
public event Action OnReset;
|
||||
public event Action OnAnimationEnd;
|
||||
void LeftReset(AnimationEvent animationEvent)
|
||||
{
|
||||
OnReset?.Invoke();
|
||||
}
|
||||
void RightReset(AnimationEvent animationEvent)
|
||||
{
|
||||
OnReset?.Invoke();
|
||||
}
|
||||
void KickReset(AnimationEvent animationEvent)
|
||||
{
|
||||
OnReset?.Invoke();
|
||||
}
|
||||
void StartDamage(AnimationEvent animationEvent)
|
||||
{
|
||||
OnStartDamage?.Invoke();
|
||||
}
|
||||
void EndDamage(AnimationEvent animationEvent)
|
||||
{
|
||||
OnEndDamage?.Invoke();
|
||||
}
|
||||
|
||||
void AnimationEnd(AnimationEvent animationEvent)
|
||||
{
|
||||
OnAnimationEnd?.Invoke();
|
||||
void AnimationEnd(AnimationEvent animationEvent)
|
||||
{
|
||||
OnAnimationEnd?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4e83c467b009194790d3bcc682cfd01
|
||||
guid: 24dd5ceef3438f64ca7fb1ef7cf1711d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Creatures.Boxsack
|
||||
{
|
||||
public class BoxsackVitalReaction : MonoBehaviour, IVitalReaction
|
||||
{
|
||||
public void Hit()
|
||||
{
|
||||
//Play animation
|
||||
print("Boxsack Vital Reaction Hit");
|
||||
}
|
||||
|
||||
public void Heal()
|
||||
{
|
||||
print("Boxsack Vital Reaction Heal");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1940334a0376f544a48be3462f080cf
|
@ -2,35 +2,46 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class EnemyMove : MonoBehaviour
|
||||
namespace Creatures.Enemy
|
||||
{
|
||||
public GameObject player;
|
||||
[SerializeField]
|
||||
private float playerDetectionRadius;
|
||||
public class EnemyMove : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
[SerializeField]
|
||||
private float playerDetectionRadius;
|
||||
|
||||
private NavMeshAgent _meshAgent;
|
||||
private NavMeshAgent _meshAgent;
|
||||
|
||||
private bool _playerFound = false;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
_meshAgent = GetComponent<NavMeshAgent>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Vector3 playerPos = player.transform.position;
|
||||
Debug.DrawRay(transform.position, (playerPos - transform.position).normalized * playerDetectionRadius, Color.red);
|
||||
|
||||
if (!_playerFound && Physics.Raycast(transform.position, (playerPos - transform.position).normalized, out RaycastHit hit, playerDetectionRadius))
|
||||
private bool _playerFound = false;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
_playerFound = hit.collider.name == player.name;
|
||||
_meshAgent = GetComponent<NavMeshAgent>();
|
||||
}
|
||||
|
||||
if (_playerFound)
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
_meshAgent.SetDestination(playerPos);
|
||||
Vector3 playerPos = player.transform.position;
|
||||
Debug.DrawRay(transform.position, (playerPos - transform.position).normalized * playerDetectionRadius, Color.red);
|
||||
|
||||
if (!_playerFound &&
|
||||
Physics.Raycast(transform.position, (playerPos - transform.position).normalized, out RaycastHit hit, playerDetectionRadius, LayerMask.GetMask("Player")))
|
||||
{
|
||||
_playerFound = true;
|
||||
}
|
||||
|
||||
|
||||
if (_playerFound)
|
||||
{
|
||||
_meshAgent.SetDestination(playerPos);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.color = Color.green;
|
||||
Gizmos.DrawWireSphere(transform.position, playerDetectionRadius);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Creatures.Enemy
|
||||
{
|
||||
public class EnemyVitalReaction : MonoBehaviour, IVitalReaction
|
||||
{
|
||||
public void Hit()
|
||||
{
|
||||
print("Enemy Vital Reaction Hit");
|
||||
}
|
||||
|
||||
public void Heal()
|
||||
{
|
||||
print("Enemy Vital Reaction Heal");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54c8ceddec4e45a4299dad732c0f50a8
|
@ -0,0 +1,8 @@
|
||||
namespace Creatures
|
||||
{
|
||||
public interface IVitalReaction
|
||||
{
|
||||
void Hit();
|
||||
void Heal();
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a7cf8275d0b83743b944ac633aefc81
|
@ -1,35 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraMove : MonoBehaviour
|
||||
{
|
||||
private Transform _cameraTransform;
|
||||
private Transform _player;
|
||||
private Vector3 _camOffset;
|
||||
private float _followspeed;
|
||||
public void initialize(Transform player, Vector3 camOffset, float followspeed, Transform cameraTransform)
|
||||
{
|
||||
_player = player;
|
||||
_camOffset = camOffset;
|
||||
_followspeed = followspeed;
|
||||
_cameraTransform = cameraTransform;
|
||||
|
||||
InitPosition();
|
||||
}
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void InitPosition()
|
||||
{
|
||||
Vector3 desiredCamPos = _player.position+_camOffset;
|
||||
_cameraTransform.position = desiredCamPos;
|
||||
_cameraTransform.LookAt(_player);
|
||||
}
|
||||
|
||||
public void MoveCamera()
|
||||
{
|
||||
Vector3 desiredCamPos = _player.position+_camOffset;
|
||||
_cameraTransform.position = desiredCamPos;
|
||||
_cameraTransform.LookAt(_player);
|
||||
|
||||
_cameraTransform.position = Vector3.Lerp(_cameraTransform.position, desiredCamPos, _followspeed*Time.deltaTime);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eff458243619d614c868620fbf434a03
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Creatures.Player.Movement
|
||||
{
|
||||
public class CameraMove : MonoBehaviour
|
||||
{
|
||||
private Transform _cameraTransform;
|
||||
private Transform _player;
|
||||
private Vector3 _camOffset;
|
||||
private float _followspeed;
|
||||
public void initialize(Transform player, Vector3 camOffset, float followspeed, Transform cameraTransform)
|
||||
{
|
||||
_player = player;
|
||||
_camOffset = camOffset;
|
||||
_followspeed = followspeed;
|
||||
_cameraTransform = cameraTransform;
|
||||
|
||||
InitPosition();
|
||||
}
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void InitPosition()
|
||||
{
|
||||
Vector3 desiredCamPos = _player.position+_camOffset;
|
||||
_cameraTransform.position = desiredCamPos;
|
||||
_cameraTransform.LookAt(_player);
|
||||
}
|
||||
|
||||
public void MoveCamera()
|
||||
{
|
||||
Vector3 desiredCamPos = _player.position+_camOffset;
|
||||
_cameraTransform.position = desiredCamPos;
|
||||
_cameraTransform.LookAt(_player);
|
||||
|
||||
_cameraTransform.position = Vector3.Lerp(_cameraTransform.position, desiredCamPos, _followspeed*Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Creatures.Player.Movement
|
||||
{
|
||||
public class PlayerAimRotate : MonoBehaviour
|
||||
{
|
||||
Canvas _canvas;
|
||||
|
||||
public void initialize(Canvas canvas)
|
||||
{
|
||||
_canvas = canvas;
|
||||
}
|
||||
|
||||
Vector3 _lastLookTarget;
|
||||
public Vector3 AimTarget(float minAimDistance, float maxAimDistance, Camera camera, Vector3 mouseInput)
|
||||
{
|
||||
Ray ray = camera.ScreenPointToRay(mouseInput); // Cast a ray from the mouse position
|
||||
Plane plane = new Plane(Vector3.up, transform.position); // Assume a horizontal plane (y-axis)
|
||||
|
||||
float distance;
|
||||
if (!plane.Raycast(ray, out distance)) // If the ray hits the plane
|
||||
{
|
||||
return _lastLookTarget;
|
||||
}
|
||||
|
||||
Vector3 targetPoint = ray.GetPoint(distance);
|
||||
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(transform.position, (targetPoint - transform.position).normalized, out hit, maxAimDistance, LayerMask.GetMask("Enemy")))
|
||||
{
|
||||
Vector3 aimTargetPosition = hit.collider.transform.position;
|
||||
float distanceToTarget = Vector3.Distance(transform.position, aimTargetPosition);
|
||||
|
||||
float assistStrength = Mathf.Clamp(1-((maxAimDistance - minAimDistance) / (distanceToTarget - minAimDistance)), 0f, .6f);
|
||||
|
||||
targetPoint = Vector3.Lerp(targetPoint, aimTargetPosition, assistStrength);
|
||||
//targetPoint = hit.collider.transform.position;
|
||||
}
|
||||
_lastLookTarget = new Vector3(targetPoint.x, transform.position.y, targetPoint.z);
|
||||
|
||||
return _lastLookTarget;
|
||||
}
|
||||
|
||||
public void ApplyRotation(Vector3 aimTarget)
|
||||
{
|
||||
aimTarget.y = _canvas.transform.position.y;
|
||||
_canvas.transform.LookAt(aimTarget);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Creatures.Player.Movement
|
||||
{
|
||||
public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
|
||||
CharacterController _controller;
|
||||
private TrailRenderer _dashTrail;
|
||||
public void initialize(CharacterController controller, TrailRenderer dashTrail)
|
||||
{
|
||||
_controller = controller;
|
||||
_dashTrail = dashTrail;
|
||||
}
|
||||
|
||||
public void ApplyMovement(Vector3 moveDir, Vector3 lookTarget, float moveSpeed)
|
||||
{
|
||||
if (!_dashing)
|
||||
{
|
||||
transform.LookAt(lookTarget);
|
||||
_controller.Move(moveSpeed * moveDir * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 _lastMoveDir = Vector3.zero;
|
||||
public Vector3 GetMoveDirection(Vector3 input, Transform cameraTransform)
|
||||
{
|
||||
Quaternion camRotation = Quaternion.Euler(0f, cameraTransform.rotation.eulerAngles.y, 0f);
|
||||
input = camRotation * input;
|
||||
|
||||
_lastMoveDir = input;
|
||||
return input;
|
||||
}
|
||||
|
||||
public Vector3 Gravity()
|
||||
{
|
||||
return Physics.gravity;
|
||||
}
|
||||
|
||||
private bool _dashing = false;
|
||||
private bool _dashPossible = true;
|
||||
|
||||
public void Dash(float dashTime, float dashCooldownTime, float dashSpeed, bool sprintPerformed, bool attacking)
|
||||
{
|
||||
if (sprintPerformed && !attacking && !_dashing && _dashPossible)
|
||||
{
|
||||
StartCoroutine(DashCoroutine(dashTime, dashCooldownTime, dashSpeed));
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator DashCoroutine(float dashTime, float dashCooldownTime, float dashSpeed)
|
||||
{
|
||||
_dashing = true;
|
||||
_dashPossible = false;
|
||||
_dashTrail.emitting = true;
|
||||
|
||||
float startTime = Time.time;
|
||||
while(Time.time < startTime + dashTime)
|
||||
{
|
||||
_controller.Move(_lastMoveDir * dashSpeed * Time.deltaTime);
|
||||
yield return null;
|
||||
}
|
||||
_dashing = false;
|
||||
_dashTrail.emitting = false;
|
||||
|
||||
StartCoroutine(DashCooldown(dashCooldownTime));
|
||||
}
|
||||
|
||||
private IEnumerator DashCooldown(float dashCooldownTime)
|
||||
{
|
||||
float startTime = Time.time;
|
||||
while(Time.time < startTime + dashCooldownTime)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
_dashPossible = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Creatures.Player.Movement
|
||||
{
|
||||
public class PlayerRotate : MonoBehaviour
|
||||
{
|
||||
public Vector3 LookTarget(Vector3 moveDir)
|
||||
{
|
||||
moveDir.y = 0;
|
||||
return transform.position + moveDir;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using Creatures;
|
||||
using Creatures.Player;
|
||||
using Creatures.Player.Movement;
|
||||
using UnityEngine;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
@ -32,9 +35,6 @@ public class Player : MonoBehaviour
|
||||
private float maxAimDistance;
|
||||
[SerializeField]
|
||||
private Canvas aimCanvas;
|
||||
[SerializeField]
|
||||
[Range(0f, 20f)]
|
||||
private float detectionAngle=5f;
|
||||
|
||||
[Header("Dash")]
|
||||
[Range(0f, 100f)]
|
||||
@ -74,6 +74,7 @@ public class Player : MonoBehaviour
|
||||
private PlayerAimRotate _playerAimRotate;
|
||||
private PlayerAttack _playerAttack;
|
||||
private CameraMove _cameraMove;
|
||||
private PlayerVitalReaction _playerVitalReaction;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
@ -86,17 +87,15 @@ void SetupGame()
|
||||
|
||||
_camera = _cameraGameObject.GetComponent<Camera>();
|
||||
_controller = GetComponent<CharacterController>();
|
||||
|
||||
_playerVitalReaction = gameObject.AddComponent<PlayerVitalReaction>();
|
||||
_playerRotate = gameObject.AddComponent<PlayerRotate>();
|
||||
|
||||
_playerAimRotate = gameObject.AddComponent<PlayerAimRotate>();
|
||||
_playerAimRotate.initialize(aimCanvas);
|
||||
|
||||
_animate = _animator.gameObject.AddComponent<Animate>();
|
||||
_animate.initialize(_animator);
|
||||
_playerAttack = gameObject.AddComponent<PlayerAttack>();
|
||||
_playerAttack.initialize(_inputManager, _enemyLayer, _animate, _hurtBox, _availableAttacks, _baseDamage, _comboStep, _comboCurve);
|
||||
|
||||
_playerMove = gameObject.AddComponent<PlayerMove>();
|
||||
_playerMove.initialize(_controller, dashTrail);
|
||||
_cameraMove = gameObject.AddComponent<CameraMove>();
|
||||
|
@ -1,48 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerAimRotate : MonoBehaviour
|
||||
{
|
||||
Canvas _canvas;
|
||||
|
||||
public void initialize(Canvas canvas)
|
||||
{
|
||||
_canvas = canvas;
|
||||
}
|
||||
|
||||
Vector3 _lastLookTarget;
|
||||
public Vector3 AimTarget(float minAimDistance, float maxAimDistance, Camera camera, Vector3 mouseInput)
|
||||
{
|
||||
Ray ray = camera.ScreenPointToRay(mouseInput); // Cast a ray from the mouse position
|
||||
Plane plane = new Plane(Vector3.up, transform.position); // Assume a horizontal plane (y-axis)
|
||||
|
||||
float distance;
|
||||
if (!plane.Raycast(ray, out distance)) // If the ray hits the plane
|
||||
{
|
||||
return _lastLookTarget;
|
||||
}
|
||||
|
||||
Vector3 targetPoint = ray.GetPoint(distance);
|
||||
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(transform.position, (targetPoint - transform.position).normalized, out hit, maxAimDistance, LayerMask.GetMask("Enemy")))
|
||||
{
|
||||
Vector3 aimTargetPosition = hit.collider.transform.position;
|
||||
float distanceToTarget = Vector3.Distance(transform.position, aimTargetPosition);
|
||||
|
||||
float assistStrength = Mathf.Clamp(1-((maxAimDistance - minAimDistance) / (distanceToTarget - minAimDistance)), 0f, .6f);
|
||||
|
||||
targetPoint = Vector3.Lerp(targetPoint, aimTargetPosition, assistStrength);
|
||||
//targetPoint = hit.collider.transform.position;
|
||||
}
|
||||
_lastLookTarget = new Vector3(targetPoint.x, transform.position.y, targetPoint.z);
|
||||
|
||||
return _lastLookTarget;
|
||||
}
|
||||
|
||||
public void ApplyRotation(Vector3 aimTarget)
|
||||
{
|
||||
aimTarget.y = _canvas.transform.position.y;
|
||||
_canvas.transform.LookAt(aimTarget);
|
||||
}
|
||||
}
|
@ -1,144 +1,151 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using Random = System.Random;
|
||||
|
||||
public class PlayerAttack : MonoBehaviour
|
||||
namespace Creatures.Player.Movement
|
||||
{
|
||||
private InputManager _inputManager;
|
||||
private LayerMask _enemyLayermask;
|
||||
private Animate _animate;
|
||||
private Collider _hurtbox;
|
||||
private string[] _availableAttacks;
|
||||
private float _baseDamage;
|
||||
private float _comboStep;
|
||||
private AnimationCurve _comboCurve;
|
||||
public void initialize(InputManager inputManager, LayerMask enemyLayermask, Animate animate, Collider hurtbox, string[] availableAttacks, float baseDamage, float comboStep, AnimationCurve comboCurve)
|
||||
public class PlayerAttack : MonoBehaviour
|
||||
{
|
||||
_inputManager = inputManager;
|
||||
_enemyLayermask = enemyLayermask;
|
||||
_hurtbox = hurtbox;
|
||||
_animate = animate;
|
||||
_availableAttacks = availableAttacks;
|
||||
_baseDamage = baseDamage;
|
||||
_comboStep = comboStep;
|
||||
_comboCurve = comboCurve;
|
||||
|
||||
OnEnable();
|
||||
}
|
||||
|
||||
#region Event Setup
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_animate != null)
|
||||
private InputManager _inputManager;
|
||||
private LayerMask _enemyLayermask;
|
||||
private Animate _animate;
|
||||
private Collider _hurtbox;
|
||||
private string[] _availableAttacks;
|
||||
private float _baseDamage;
|
||||
private float _comboStep;
|
||||
private AnimationCurve _comboCurve;
|
||||
public void initialize(InputManager inputManager, LayerMask enemyLayermask, Animate animate, Collider hurtbox, string[] availableAttacks, float baseDamage, float comboStep, AnimationCurve comboCurve)
|
||||
{
|
||||
_animate.OnReset += _onResetHandler;
|
||||
_animate.OnStartDamage += _onStartDamageHandler;
|
||||
_animate.OnEndDamage += _onEndDamageHandler;
|
||||
_animate.OnAnimationEnd += _onAnimationEndHandler;
|
||||
_inputManager = inputManager;
|
||||
_enemyLayermask = enemyLayermask;
|
||||
_hurtbox = hurtbox;
|
||||
_animate = animate;
|
||||
_availableAttacks = availableAttacks;
|
||||
_baseDamage = baseDamage;
|
||||
_comboStep = comboStep;
|
||||
_comboCurve = comboCurve;
|
||||
|
||||
OnEnable();
|
||||
}
|
||||
|
||||
_canAttack = true;
|
||||
_attacking = false;
|
||||
_damageEnded = true;
|
||||
_currentDamageMultiplier = new Dictionary<int, float>();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_animate.OnReset -= _onResetHandler;
|
||||
_animate.OnStartDamage -= _onStartDamageHandler;
|
||||
_animate.OnEndDamage -= _onEndDamageHandler;
|
||||
_animate.OnAnimationEnd -= _onAnimationEndHandler;
|
||||
}
|
||||
|
||||
private void _onResetHandler()
|
||||
{
|
||||
_canAttack = true;
|
||||
}
|
||||
|
||||
private void _onAnimationEndHandler()
|
||||
{
|
||||
_attacking = false;
|
||||
_currentDamageMultiplier = new Dictionary<int, float>();
|
||||
}
|
||||
#region Event Setup
|
||||
|
||||
private void _onStartDamageHandler()
|
||||
{
|
||||
StartCoroutine(DealDamage());
|
||||
}
|
||||
|
||||
private void _onEndDamageHandler()
|
||||
{
|
||||
_damageEnded = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private bool _attacking=false;
|
||||
private bool _canAttack = true;
|
||||
private int _attack = 0;
|
||||
public bool Attack()
|
||||
{
|
||||
if (_canAttack && _inputManager.attackPerformed)
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_attack >= 2 || _animate.IsCurrentAnimation("Blend Tree"))
|
||||
if (_animate != null)
|
||||
{
|
||||
_attack = 0;
|
||||
_animate.OnReset += _onResetHandler;
|
||||
_animate.OnStartDamage += _onStartDamageHandler;
|
||||
_animate.OnEndDamage += _onEndDamageHandler;
|
||||
_animate.OnAnimationEnd += _onAnimationEndHandler;
|
||||
}
|
||||
|
||||
_animate.TriggerAnimation(_availableAttacks[_attack]);
|
||||
|
||||
_canAttack = false;
|
||||
_attack++;
|
||||
_attacking = true;
|
||||
|
||||
_canAttack = true;
|
||||
_attacking = false;
|
||||
_damageEnded = true;
|
||||
_currentDamageMultiplier = new Dictionary<int, float>();
|
||||
}
|
||||
|
||||
return _attacking;
|
||||
}
|
||||
|
||||
private bool _damageEnded = true;
|
||||
IEnumerator DealDamage()
|
||||
{
|
||||
List<Collider> damagedColliders = new List<Collider>();
|
||||
_damageEnded = false;
|
||||
while (!_damageEnded)
|
||||
private void OnDisable()
|
||||
{
|
||||
Collider[] hitColliders = Physics.OverlapBox(_hurtbox.bounds.center, _hurtbox.bounds.extents, Quaternion.identity, _enemyLayermask);
|
||||
|
||||
foreach (Collider enemy in hitColliders)
|
||||
_animate.OnReset -= _onResetHandler;
|
||||
_animate.OnStartDamage -= _onStartDamageHandler;
|
||||
_animate.OnEndDamage -= _onEndDamageHandler;
|
||||
_animate.OnAnimationEnd -= _onAnimationEndHandler;
|
||||
}
|
||||
|
||||
private void _onResetHandler()
|
||||
{
|
||||
_canAttack = true;
|
||||
}
|
||||
|
||||
private void _onAnimationEndHandler()
|
||||
{
|
||||
_attacking = false;
|
||||
_currentDamageMultiplier = new Dictionary<int, float>();
|
||||
_lastDamageMultiplier = new Dictionary<int, float>();
|
||||
}
|
||||
|
||||
private void _onStartDamageHandler()
|
||||
{
|
||||
StartCoroutine(DealDamage());
|
||||
}
|
||||
|
||||
private void _onEndDamageHandler()
|
||||
{
|
||||
_damageEnded = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private bool _attacking=false;
|
||||
private bool _canAttack = true;
|
||||
private int _attack = 0;
|
||||
public bool Attack()
|
||||
{
|
||||
if (_canAttack && _inputManager.attackPerformed)
|
||||
{
|
||||
if (!damagedColliders.Contains(enemy))
|
||||
if (_attack >= 2 || _animate.IsCurrentAnimation("Blend Tree"))
|
||||
{
|
||||
print(enemy.gameObject.GetComponent<Vitals>().Health);
|
||||
enemy.gameObject.GetComponent<Vitals>().Health = -CalculateDamage(enemy);
|
||||
damagedColliders.Add(enemy);
|
||||
_attack = 0;
|
||||
}
|
||||
|
||||
_animate.TriggerAnimation(_availableAttacks[_attack]);
|
||||
|
||||
_canAttack = false;
|
||||
_attack++;
|
||||
_attacking = true;
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<int, float> _currentDamageMultiplier = new Dictionary<int, float>();
|
||||
float CalculateDamage(Collider enemy)
|
||||
{
|
||||
// If enemy is hit for the first time during "Combo" he gets added to the dictionary to get its own combo mult
|
||||
if (!_currentDamageMultiplier.ContainsKey(enemy.GetInstanceID()))
|
||||
{
|
||||
_currentDamageMultiplier.Add(enemy.GetInstanceID(), 0f);
|
||||
return _attacking;
|
||||
}
|
||||
// If enemy gets hit again its Combo mult is incremented
|
||||
else
|
||||
|
||||
private bool _damageEnded = true;
|
||||
Dictionary<int, float> _lastDamageMultiplier = new Dictionary<int, float>();
|
||||
Dictionary<int, float> _currentDamageMultiplier = new Dictionary<int, float>();
|
||||
IEnumerator DealDamage()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_currentDamageMultiplier[enemy.GetInstanceID()] += _comboStep * (rnd.Next(1, 10) / 10f);
|
||||
List<Collider> damagedColliders = new List<Collider>();
|
||||
_currentDamageMultiplier = new Dictionary<int, float>();
|
||||
_damageEnded = false;
|
||||
|
||||
while (!_damageEnded)
|
||||
{
|
||||
Collider[] hitColliders = Physics.OverlapBox(_hurtbox.bounds.center, _hurtbox.bounds.extents, Quaternion.identity, _enemyLayermask);
|
||||
|
||||
foreach (Collider enemy in hitColliders)
|
||||
{
|
||||
if (!damagedColliders.Contains(enemy))
|
||||
{
|
||||
enemy.gameObject.GetComponent<Vitals>().Health = -CalculateDamage(enemy);
|
||||
damagedColliders.Add(enemy);
|
||||
}
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
_lastDamageMultiplier = _currentDamageMultiplier;
|
||||
}
|
||||
|
||||
float CalculateDamage(Collider enemy)
|
||||
{
|
||||
print(_lastDamageMultiplier.ContainsKey(enemy.GetInstanceID()));
|
||||
// If enemy is hit for the first time during "Combo" he gets added to the dictionary to get its own combo mult
|
||||
if (!_lastDamageMultiplier.ContainsKey(enemy.GetInstanceID()))
|
||||
{
|
||||
_currentDamageMultiplier.Add(enemy.GetInstanceID(), 0f);
|
||||
}
|
||||
// If enemy gets hit again its Combo mult is incremented
|
||||
else if(_lastDamageMultiplier.ContainsKey(enemy.GetInstanceID()))
|
||||
{
|
||||
_currentDamageMultiplier.Add(enemy.GetInstanceID(), _lastDamageMultiplier[enemy.GetInstanceID()]);
|
||||
Random rnd = new Random();
|
||||
_currentDamageMultiplier[enemy.GetInstanceID()] += _comboStep * (rnd.Next(1, 10) / 10f);
|
||||
}
|
||||
|
||||
return _baseDamage * _comboCurve.Evaluate(_currentDamageMultiplier[enemy.GetInstanceID()]);
|
||||
}
|
||||
|
||||
return _baseDamage * _comboCurve.Evaluate(_currentDamageMultiplier[enemy.GetInstanceID()]);
|
||||
}
|
||||
}
|
||||
|
@ -1,82 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
|
||||
CharacterController _controller;
|
||||
private TrailRenderer _dashTrail;
|
||||
public void initialize(CharacterController controller, TrailRenderer dashTrail)
|
||||
{
|
||||
_controller = controller;
|
||||
_dashTrail = dashTrail;
|
||||
}
|
||||
|
||||
public void ApplyMovement(Vector3 moveDir, Vector3 lookTarget, float moveSpeed)
|
||||
{
|
||||
if (!_dashing)
|
||||
{
|
||||
transform.LookAt(lookTarget);
|
||||
_controller.Move(moveSpeed * moveDir * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 _lastMoveDir = Vector3.zero;
|
||||
public Vector3 GetMoveDirection(Vector3 input, Transform cameraTransform)
|
||||
{
|
||||
Quaternion camRotation = Quaternion.Euler(0f, cameraTransform.rotation.eulerAngles.y, 0f);
|
||||
input = camRotation * input;
|
||||
|
||||
_lastMoveDir = input;
|
||||
return input;
|
||||
}
|
||||
|
||||
public Vector3 Gravity()
|
||||
{
|
||||
return Physics.gravity;
|
||||
}
|
||||
|
||||
private bool _dashing = false;
|
||||
private bool _dashPossible = true;
|
||||
|
||||
public void Dash(float dashTime, float dashCooldownTime, float dashSpeed, bool sprintPerformed, bool attacking)
|
||||
{
|
||||
if (sprintPerformed && !attacking && !_dashing && _dashPossible)
|
||||
{
|
||||
StartCoroutine(DashCoroutine(dashTime, dashCooldownTime, dashSpeed));
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator DashCoroutine(float dashTime, float dashCooldownTime, float dashSpeed)
|
||||
{
|
||||
_dashing = true;
|
||||
_dashPossible = false;
|
||||
_dashTrail.emitting = true;
|
||||
|
||||
float startTime = Time.time;
|
||||
while(Time.time < startTime + dashTime)
|
||||
{
|
||||
_controller.Move(_lastMoveDir * dashSpeed * Time.deltaTime);
|
||||
yield return null;
|
||||
}
|
||||
_dashing = false;
|
||||
_dashTrail.emitting = false;
|
||||
|
||||
StartCoroutine(DashCooldown(dashCooldownTime));
|
||||
}
|
||||
|
||||
private IEnumerator DashCooldown(float dashCooldownTime)
|
||||
{
|
||||
float startTime = Time.time;
|
||||
while(Time.time < startTime + dashCooldownTime)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
_dashPossible = true;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerRotate : MonoBehaviour
|
||||
{
|
||||
public Vector3 LookTarget(Vector3 moveDir)
|
||||
{
|
||||
moveDir.y = 0;
|
||||
return transform.position + moveDir;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Creatures.Player
|
||||
{
|
||||
public class PlayerVitalReaction : MonoBehaviour, IVitalReaction
|
||||
{
|
||||
public void Hit()
|
||||
{
|
||||
//Play animation
|
||||
print("Player Vital Reaction Hit");
|
||||
}
|
||||
|
||||
public void Heal()
|
||||
{
|
||||
//Play animation
|
||||
print("Player Vital Reaction Heal");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1bddc30b11c851442a1cf3a53f50e95a
|
54
twinStickCrawler/Assets/Scripts/Creatures/UI/DamageNumber.cs
Normal file
54
twinStickCrawler/Assets/Scripts/Creatures/UI/DamageNumber.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Random = System.Random;
|
||||
|
||||
namespace UI.WorldUI
|
||||
{
|
||||
public class DamageNumber : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
TextMeshProUGUI textMesh;
|
||||
[SerializeField]
|
||||
private float speed;
|
||||
[SerializeField]
|
||||
private float moveSpeed=10f;
|
||||
|
||||
private Camera mainCamera;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
speed += rnd.Next(-10, 10)/100f;
|
||||
mainCamera = Camera.main;
|
||||
|
||||
StartCoroutine(Animate());
|
||||
}
|
||||
|
||||
IEnumerator Animate()
|
||||
{
|
||||
textMesh.color = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b, 1);
|
||||
Billboard();
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
while (textMesh.color.a > 0)
|
||||
{
|
||||
float newAlpha = textMesh.color.a - Time.deltaTime * speed / 255f; // Reduce alpha in the float range
|
||||
newAlpha = Mathf.Clamp01(newAlpha); // Ensure it remains between 0 and 1
|
||||
textMesh.color = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b, newAlpha); // Assign the new alpha value
|
||||
this.transform.position = new Vector3(transform.position.x, transform.position.y+moveSpeed*Time.deltaTime, transform.position.z);
|
||||
|
||||
Billboard();
|
||||
|
||||
yield return null;
|
||||
}
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
void Billboard()
|
||||
{
|
||||
transform.LookAt(transform.position + mainCamera.transform.rotation * Vector3.forward, mainCamera.transform.rotation * Vector3.up);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using Creatures;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class Vitals : MonoBehaviour
|
||||
@ -10,7 +12,10 @@ public class Vitals : MonoBehaviour
|
||||
[SerializeField]
|
||||
private GameObject damagePrefab;
|
||||
|
||||
private IVitalReaction _reaction;
|
||||
|
||||
private float health;
|
||||
|
||||
public float Health
|
||||
{
|
||||
get
|
||||
@ -21,15 +26,15 @@ public float Health
|
||||
{
|
||||
GameObject damageInstance = Instantiate(damagePrefab, canvas.transform);
|
||||
damageInstance.transform.localPosition = Vector3.zero;
|
||||
|
||||
damageInstance.GetComponent<TextMeshProUGUI>().SetText(Mathf.Abs((int)value).ToString());
|
||||
|
||||
if (value < 0)
|
||||
{
|
||||
//hit
|
||||
_reaction.Hit();
|
||||
}
|
||||
else
|
||||
{
|
||||
//heal
|
||||
_reaction.Heal();
|
||||
}
|
||||
|
||||
health += value;
|
||||
@ -41,4 +46,9 @@ void Start()
|
||||
{
|
||||
health = initHealth;
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_reaction = GetComponent<IVitalReaction>();
|
||||
}
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Random = System.Random;
|
||||
|
||||
public class DamageNumber : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
TextMeshProUGUI textMesh;
|
||||
[SerializeField]
|
||||
private float speed;
|
||||
[SerializeField]
|
||||
private float moveSpeed=10f;
|
||||
|
||||
private Camera mainCamera;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
speed += rnd.Next(-10, 10)/100f;
|
||||
mainCamera = Camera.main;
|
||||
|
||||
StartCoroutine(Animate());
|
||||
}
|
||||
|
||||
IEnumerator Animate()
|
||||
{
|
||||
textMesh.color = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b, 1);
|
||||
transform.LookAt(transform.position - mainCamera.transform.position);
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
while (textMesh.color.a > 0)
|
||||
{
|
||||
float newAlpha = textMesh.color.a - Time.deltaTime * speed / 255f; // Reduce alpha in the float range
|
||||
newAlpha = Mathf.Clamp01(newAlpha); // Ensure it remains between 0 and 1
|
||||
textMesh.color = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b, newAlpha); // Assign the new alpha value
|
||||
|
||||
this.transform.position = new Vector3(transform.position.x, transform.position.y+moveSpeed*Time.deltaTime, transform.position.z);
|
||||
|
||||
transform.LookAt(transform.position - mainCamera.transform.position);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user