initial commit
This commit is contained in:
74
Assets/Bots/Bot.cs
Normal file
74
Assets/Bots/Bot.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class Bot : MonoBehaviour
|
||||
{
|
||||
public GameObject target;
|
||||
public LayerMask playerLayer;
|
||||
public float seeRadius = 20f;
|
||||
public float attkRadus = 2f;
|
||||
private NavMeshAgent agent;
|
||||
private Animator animator;
|
||||
private float attackCooldown = 0f;
|
||||
private int hp = 100;
|
||||
|
||||
void Start()
|
||||
{
|
||||
this.agent = this.GetComponent<NavMeshAgent>();
|
||||
this.animator = this.GetComponentInChildren<Animator>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (canSeePlayer())
|
||||
{
|
||||
if (canAttackPlayer()){
|
||||
attack();
|
||||
agent.isStopped = true;
|
||||
}else{
|
||||
agent.isStopped = false;
|
||||
agent.SetDestination(target.transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateAnimator(agent.desiredVelocity);
|
||||
}
|
||||
|
||||
private void attack(){
|
||||
attackCooldown -= Time.deltaTime;
|
||||
if (attackCooldown <= 0f){
|
||||
attackCooldown = 3f;
|
||||
this.target.GetComponent<Controls>().hp -= 10;
|
||||
this.target.GetComponent<Controls>().Damaged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool canSeePlayer()
|
||||
{
|
||||
return Physics.CheckSphere(this.transform.position, seeRadius, playerLayer);
|
||||
}
|
||||
|
||||
private bool canAttackPlayer(){
|
||||
return Physics.CheckSphere(this.transform.position, attkRadus, playerLayer);
|
||||
}
|
||||
|
||||
private void UpdateAnimator(Vector3 movement)
|
||||
{
|
||||
animator.SetFloat("Forward", movement.magnitude, 0.1f, Time.deltaTime);
|
||||
if(movement.magnitude >= 1){
|
||||
Debug.Log(Mathf.Atan2(movement.x, movement.z));
|
||||
}
|
||||
animator.SetFloat("Turn", Mathf.Atan2(movement.x, movement.z), 0.1f, Time.deltaTime);
|
||||
}
|
||||
|
||||
public void hit(){
|
||||
this.hp -= 20;
|
||||
agent.isStopped = false;
|
||||
agent.SetDestination(target.transform.position);
|
||||
if (this.hp <= 0){
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Bots/Bot.cs.meta
Normal file
11
Assets/Bots/Bot.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40f2ded2ff256cc25831dfbf6bc4a0e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
172
Assets/Bots/Bot.prefab
Normal file
172
Assets/Bots/Bot.prefab
Normal file
@@ -0,0 +1,172 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &6610855158749230800
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 6610855158749230805}
|
||||
- component: {fileID: 6610855158749230804}
|
||||
- component: {fileID: 6610855158749230803}
|
||||
- component: {fileID: 6610855158749230802}
|
||||
m_Layer: 0
|
||||
m_Name: Bot
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &6610855158749230805
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6610855158749230800}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 19.65, y: 1.04, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 6610855159095585308}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!136 &6610855158749230804
|
||||
CapsuleCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6610855158749230800}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
m_Radius: 0.5
|
||||
m_Height: 2
|
||||
m_Direction: 1
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!195 &6610855158749230803
|
||||
NavMeshAgent:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6610855158749230800}
|
||||
m_Enabled: 1
|
||||
m_AgentTypeID: 0
|
||||
m_Radius: 0.5
|
||||
m_Speed: 3.5
|
||||
m_Acceleration: 8
|
||||
avoidancePriority: 50
|
||||
m_AngularSpeed: 120
|
||||
m_StoppingDistance: 0
|
||||
m_AutoTraverseOffMeshLink: 1
|
||||
m_AutoBraking: 1
|
||||
m_AutoRepath: 1
|
||||
m_Height: 2
|
||||
m_BaseOffset: 1
|
||||
m_WalkableMask: 4294967295
|
||||
m_ObstacleAvoidanceType: 4
|
||||
--- !u!114 &6610855158749230802
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6610855158749230800}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 40f2ded2ff256cc25831dfbf6bc4a0e7, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
target: {fileID: 0}
|
||||
playerLayer:
|
||||
serializedVersion: 2
|
||||
m_Bits: 64
|
||||
seeRadius: 20
|
||||
attkRadus: 3
|
||||
--- !u!1001 &6610855159095718196
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_Modification:
|
||||
m_TransformParent: {fileID: 6610855158749230805}
|
||||
m_Modifications:
|
||||
- target: {fileID: 100168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: Ethan
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_RootOrder
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalScale.x
|
||||
value: 1.5
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalScale.y
|
||||
value: 1.5
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalScale.z
|
||||
value: 1.5
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: -1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 9500000, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_Controller
|
||||
value:
|
||||
objectReference: {fileID: 9100000, guid: e2cf68ff4b1ffda45a77f7307dd789b9, type: 2}
|
||||
- target: {fileID: 9500000, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
propertyPath: m_ApplyRootMotion
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
--- !u!4 &6610855159095585308 stripped
|
||||
Transform:
|
||||
m_CorrespondingSourceObject: {fileID: 400168, guid: b235179bd2a63d1468dd430670338c55, type: 3}
|
||||
m_PrefabInstance: {fileID: 6610855159095718196}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
7
Assets/Bots/Bot.prefab.meta
Normal file
7
Assets/Bots/Bot.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90ab65bd2a9b2a9d2b30337117684c2a
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user