Merge branch 'staging2' into combatscene
This commit is contained in:
@@ -1,21 +1,84 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class SlimeAI : MonoBehaviour
|
||||
{
|
||||
|
||||
Animator animator;
|
||||
float playerDistance;
|
||||
GameObject player;
|
||||
int HP;
|
||||
|
||||
//[SerializeField]
|
||||
//private UnityEvent onAttack;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
player = GameObject.FindWithTag("Player");
|
||||
HP = 10;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
playerDistance = Vector3.Distance(player.transform.position, transform.position);
|
||||
if (playerDistance < 1.5) //Attack
|
||||
{
|
||||
animator.SetBool("EnemyInAttackRange", true);
|
||||
animator.SetBool("EnemyInAggroRange", true);
|
||||
animator.SetBool("EnemyInVisionRange", true);
|
||||
Rotate();
|
||||
}
|
||||
else if (playerDistance < 5) //Chase
|
||||
{
|
||||
animator.SetBool("EnemyInAttackRange", false);
|
||||
animator.SetBool("EnemyInAggroRange", true);
|
||||
animator.SetBool("EnemyInVisionRange", true);
|
||||
Rotate();
|
||||
Move();
|
||||
}
|
||||
else if (playerDistance < 8) //Stare
|
||||
{
|
||||
animator.SetBool("EnemyInAttackRange", false);
|
||||
animator.SetBool("EnemyInAggroRange", false);
|
||||
animator.SetBool("EnemyInVisionRange", true);
|
||||
Rotate();
|
||||
}
|
||||
else //Idle
|
||||
{
|
||||
animator.SetBool("EnemyInAttackRange", false);
|
||||
animator.SetBool("EnemyInAggroRange", false);
|
||||
animator.SetBool("EnemyInVisionRange", false);
|
||||
}
|
||||
if (HP <= 0)
|
||||
{
|
||||
animator.SetBool("Dead", true);
|
||||
}
|
||||
if (animator.GetBool("DeathComplete"))
|
||||
{
|
||||
print("asd");
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
void Rotate()
|
||||
{
|
||||
// Rotate the forward vector towards the target direction by one step
|
||||
Vector3 newDirection = Vector3.RotateTowards(transform.forward, player.transform.position - transform.position, 1.0f * Time.deltaTime, 0.0f);
|
||||
|
||||
// Calculate a rotation a step closer to the target and applies rotation to this object
|
||||
transform.rotation = Quaternion.LookRotation(newDirection);
|
||||
}
|
||||
void Move()
|
||||
{
|
||||
transform.position += transform.forward * Time.deltaTime * 1.0f;
|
||||
}
|
||||
|
||||
public void GetHit(int dmg)
|
||||
{
|
||||
HP -= dmg;
|
||||
}
|
||||
}
|
||||
|
||||
36
Assets/Project Files/Scripts/Arlo/SlimeDeath.cs
Normal file
36
Assets/Project Files/Scripts/Arlo/SlimeDeath.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class death : StateMachineBehaviour
|
||||
{
|
||||
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
|
||||
//override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
//{
|
||||
//
|
||||
//}
|
||||
|
||||
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
|
||||
//override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
//{
|
||||
//
|
||||
//}
|
||||
|
||||
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
|
||||
//override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
//{
|
||||
//
|
||||
//}
|
||||
|
||||
// OnStateMove is called right after Animator.OnAnimatorMove()
|
||||
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
//{
|
||||
// // Implement code that processes and affects root motion
|
||||
//}
|
||||
|
||||
// OnStateIK is called right after Animator.OnAnimatorIK()
|
||||
//override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
//{
|
||||
// // Implement code that sets up animation IK (inverse kinematics)
|
||||
//}
|
||||
}
|
||||
11
Assets/Project Files/Scripts/Arlo/SlimeDeath.cs.meta
Normal file
11
Assets/Project Files/Scripts/Arlo/SlimeDeath.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c7f89faf36f41b418e5105a12c34cdb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user