updated
This commit is contained in:
8
Assets/Scripts/Enemies/AI.meta
Normal file
8
Assets/Scripts/Enemies/AI.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cad50f842393434fa2dc09cc614fd93
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
64
Assets/Scripts/Enemies/AI/SkinlessMonsterAnimator.cs
Normal file
64
Assets/Scripts/Enemies/AI/SkinlessMonsterAnimator.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Rendering;
|
||||
using UnityEngine;
|
||||
|
||||
public class SkinlessMonsterAnimator : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Animator animator;
|
||||
private float speed = 0f;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
animator.SetFloat("speed", speed);
|
||||
|
||||
}
|
||||
|
||||
public void StartMoving()
|
||||
{
|
||||
speed = 1;
|
||||
|
||||
|
||||
}
|
||||
public void StopMoving()
|
||||
{
|
||||
speed = 0;
|
||||
|
||||
}
|
||||
public void Attack()
|
||||
{
|
||||
animator.SetTrigger("Attack");
|
||||
}
|
||||
/// <summary>
|
||||
/// 0,1,2,3
|
||||
/// </summary>
|
||||
/// <param name="attackType"></param>
|
||||
public void SetAttackType(int attackType)
|
||||
{
|
||||
animator.SetInteger("AttackIndex", attackType);
|
||||
}
|
||||
public void InLight()
|
||||
{
|
||||
animator.SetBool("InLight", true);
|
||||
}
|
||||
public void NotInLight()
|
||||
{
|
||||
animator.SetBool("InLight", false);
|
||||
}
|
||||
|
||||
public void AttackScream()
|
||||
{
|
||||
animator.SetTrigger("AttackScream");
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Enemies/AI/SkinlessMonsterAnimator.cs.meta
Normal file
11
Assets/Scripts/Enemies/AI/SkinlessMonsterAnimator.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25b1ea1a67bb5ac46ab647a1cd794807
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
100
Assets/Scripts/Enemies/AI/SkinlessMonsterComponent.cs
Normal file
100
Assets/Scripts/Enemies/AI/SkinlessMonsterComponent.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
|
||||
|
||||
|
||||
public class SkinlessMonsterComponent : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private NavMeshAgent agent;
|
||||
[SerializeField]
|
||||
private SkinlessMonsterAnimator animator;
|
||||
|
||||
private bool inRangeOfTarget = false;
|
||||
private bool atTarget = false;
|
||||
[SerializeField]
|
||||
private float atTargetDistance = 3;
|
||||
private TargetInformation target;
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
//Update booleans for movement
|
||||
float distToTarget = Vector3.Distance(target.target.transform.position, agent.transform.position);
|
||||
atTarget = atTargetDistance >= distToTarget;
|
||||
if (target.hasDamageRange)
|
||||
{
|
||||
inRangeOfTarget = target.damageRange <= distToTarget;
|
||||
}
|
||||
else
|
||||
{
|
||||
inRangeOfTarget = false;
|
||||
}
|
||||
//Perform actions.
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
/*
|
||||
STANDARD BEHAVIOR:
|
||||
- OnSeeing/Hearing Player:
|
||||
- Run towards Player
|
||||
- OnHearing Bolt:
|
||||
- Run towards bolt
|
||||
- OnSeeing Flare:
|
||||
- Run towards flare if not within (flareRange + flareMargin).
|
||||
- This acts like if you are far enough away that you don't feel the pain of the flare
|
||||
- OnSeeing FlareBeacon:
|
||||
- Run away if within (flareBeaconRange + flareBeaconMargin).
|
||||
|
||||
*/
|
||||
|
||||
//Runs towards target. If its meant to be hostile, it will melee attack once in range.
|
||||
public void Target(GameObject obj,bool hostile=false)
|
||||
{
|
||||
if(target.target!= obj)
|
||||
{
|
||||
//target = new TargetInformation(obj,hostile,false,runTowards:true);
|
||||
}
|
||||
}
|
||||
//Runs towards flare such that it stops randomly within margin before range.
|
||||
public void TargetFlare(GameObject obj,float range,float margin)
|
||||
{
|
||||
if(target.target != obj)
|
||||
{
|
||||
//target = new TargetInformation(obj, false, true, range, margin,runTowards:true);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Runs away from object. A minimum range is specified where it no longer takes damage, and a minimum margin is
|
||||
/// speicifed where it can stop running.
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <param name="minRange"></param>
|
||||
/// <param name="minMargin"></param>
|
||||
public void RunAwayFrom(GameObject obj,float minRange,float minMargin) {
|
||||
if(target.target != obj)
|
||||
{
|
||||
//target = new TargetInformation(obj, false, true, minRange, minMargin, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
class TargetInformation
|
||||
{
|
||||
|
||||
public GameObject target;
|
||||
public bool isHostile;
|
||||
public bool hasDamageRange;
|
||||
public float damageRange;
|
||||
public float damageMargin;
|
||||
public bool runTowards;
|
||||
|
||||
}
|
11
Assets/Scripts/Enemies/AI/SkinlessMonsterComponent.cs.meta
Normal file
11
Assets/Scripts/Enemies/AI/SkinlessMonsterComponent.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ef96d673cf373444b2ae89ea9588ee1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class FlareBeacon : MonoBehaviour
|
||||
{
|
||||
@ -10,6 +11,8 @@ public class FlareBeacon : MonoBehaviour
|
||||
private float duration = 5f;
|
||||
|
||||
private List<GameObject> inRange= new List<GameObject>();
|
||||
[SerializeField]
|
||||
private NavMeshObstacle obstacle;
|
||||
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
@ -39,7 +42,7 @@ public class FlareBeacon : MonoBehaviour
|
||||
if(Physics.Raycast(r,out hit)){
|
||||
// transform.position = hit.point;
|
||||
}
|
||||
|
||||
obstacle.radius = this.range / 10;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
Reference in New Issue
Block a user