to master merge

This commit is contained in:
2022-05-02 16:09:20 +03:00
parent 6571056d18
commit 2beb3298c6
10 changed files with 138 additions and 117 deletions

View File

@@ -140,31 +140,6 @@ AnimatorStateTransition:
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &-3741334239111002070
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: Dead
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102835054974116572}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1102 &-1989803667490188130
AnimatorState:
serializedVersion: 6
@@ -242,6 +217,28 @@ AnimatorStateTransition:
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &-661908585856255301
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 0}
m_Solo: 0
m_Mute: 0
m_IsExit: 1
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 2
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!91 &9100000
AnimatorController:
m_ObjectHideFlags: 0
@@ -275,18 +272,6 @@ AnimatorController:
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: Dead
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: DeathComplete
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
@@ -897,8 +882,10 @@ AnimatorState:
m_Name: Die
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
m_StateMachineBehaviours: []
m_Transitions:
- {fileID: -661908585856255301}
m_StateMachineBehaviours:
- {fileID: 7912422198382985104}
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
@@ -1080,7 +1067,7 @@ AnimatorStateMachine:
m_Position: {x: 670, y: 550, z: 0}
- serializedVersion: 1
m_State: {fileID: 1102835054974116572}
m_Position: {x: 300, y: -80, z: 0}
m_Position: {x: 40, y: 380, z: 0}
- serializedVersion: 1
m_State: {fileID: 8194647877007136643}
m_Position: {x: 300, y: 220, z: 0}
@@ -1091,14 +1078,13 @@ AnimatorStateMachine:
m_State: {fileID: -6878085496064969341}
m_Position: {x: 300, y: 300, z: 0}
m_ChildStateMachines: []
m_AnyStateTransitions:
- {fileID: -3741334239111002070}
m_AnyStateTransitions: []
m_EntryTransitions: []
m_StateMachineTransitions: {}
m_StateMachineBehaviours: []
m_AnyStatePosition: {x: 60, y: -70, z: 0}
m_AnyStatePosition: {x: 50, y: 20, z: 0}
m_EntryPosition: {x: 100, y: 150, z: 0}
m_ExitPosition: {x: 90, y: 510, z: 0}
m_ExitPosition: {x: 50, y: 440, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 1102546605246812244}
--- !u!1101 &4009614032068998235
@@ -1151,6 +1137,18 @@ AnimatorStateTransition:
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!114 &7912422198382985104
MonoBehaviour:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aa7306c35f4c27d4daefb1259633b9d0, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1102 &8194647877007136643
AnimatorState:
serializedVersion: 6

View File

@@ -19,8 +19,10 @@ public class SlimeAI : MonoBehaviour
private bool isRotatingRight = false;
private bool isWalking = false;
public UnityEvent onDeathComplete;
private bool isAttacking = false;
private float attackStartTime;
public UnityEvent onDeathComplete;
//[SerializeField]
//private UnityEvent onAttack;
@@ -29,14 +31,20 @@ public class SlimeAI : MonoBehaviour
{
animator = GetComponent<Animator>();
player = GameObject.FindWithTag("Player");
HP = 2;
HP = 0;
}
// Update is called once per frame
void Update()
{
playerDistance = Vector3.Distance(player.transform.position, transform.position);
if (HP <= 0)
{
animator.Play("Die");
onDeathComplete.Invoke();
}
if (playerDistance < 1.5) //Attack
{
animator.SetBool("Wandering", false);
@@ -44,6 +52,7 @@ public class SlimeAI : MonoBehaviour
animator.SetBool("EnemyInAggroRange", true);
animator.SetBool("EnemyInVisionRange", true);
Rotate();
Attack();
}
else if (playerDistance < 10) //Chase
{
@@ -69,12 +78,15 @@ public class SlimeAI : MonoBehaviour
animator.SetBool("EnemyInAggroRange", false);
animator.SetBool("EnemyInVisionRange", false);
}
if (!isWandering)
{
//Idle
StartCoroutine("Wander");
}
Debug.Log(isWandering);
Debug.Log(isRotatingLeft);
Debug.Log(isRotatingRight);
if (isRotatingRight == true)
{
animator.SetBool("Wandering", false);
@@ -90,18 +102,6 @@ public class SlimeAI : MonoBehaviour
animator.SetBool("Wandering", true);
transform.position += transform.forward * moveSpeed * Time.deltaTime;
}
if (HP <= 0)
{
animator.SetBool("Dead", true);
}
if (animator.GetBool("Dead"))
{
print("asd");
Destroy(this.gameObject);
onDeathComplete.Invoke();
}
@@ -124,6 +124,29 @@ public class SlimeAI : MonoBehaviour
HP -= dmg;
}
void Attack()
{
if (!isAttacking)
{
isAttacking = true;
attackStartTime = Time.time;
StartCoroutine(DelayedAttack());
}
else if (Time.time - attackStartTime > 0.833)
{
isAttacking = false;
attackStartTime = 0.0f;
}
}
IEnumerator DelayedAttack()
{
yield return new WaitForSeconds(0.2f);
Debug.Log("Attack");
//do attack e.g check for player in range/hit collider
}
IEnumerator Wander()
{
int rotTime = Random.Range(1, 3);
@@ -154,4 +177,4 @@ public class SlimeAI : MonoBehaviour
isWandering = false;
}
}
}