Make thrower enemy code
This commit is contained in:
@@ -20,7 +20,8 @@ Material:
|
|||||||
m_DoubleSidedGI: 0
|
m_DoubleSidedGI: 0
|
||||||
m_CustomRenderQueue: -1
|
m_CustomRenderQueue: -1
|
||||||
stringTagMap: {}
|
stringTagMap: {}
|
||||||
disabledShaderPasses: []
|
disabledShaderPasses:
|
||||||
|
- MOTIONVECTORS
|
||||||
m_LockedProperties:
|
m_LockedProperties:
|
||||||
m_SavedProperties:
|
m_SavedProperties:
|
||||||
serializedVersion: 3
|
serializedVersion: 3
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ Material:
|
|||||||
m_DoubleSidedGI: 0
|
m_DoubleSidedGI: 0
|
||||||
m_CustomRenderQueue: -1
|
m_CustomRenderQueue: -1
|
||||||
stringTagMap: {}
|
stringTagMap: {}
|
||||||
disabledShaderPasses: []
|
disabledShaderPasses:
|
||||||
|
- MOTIONVECTORS
|
||||||
m_LockedProperties:
|
m_LockedProperties:
|
||||||
m_SavedProperties:
|
m_SavedProperties:
|
||||||
serializedVersion: 3
|
serializedVersion: 3
|
||||||
|
|||||||
BIN
Assets/Scenes/Scene1-1.unity
LFS
BIN
Assets/Scenes/Scene1-1.unity
LFS
Binary file not shown.
72
Assets/Scripts/ThrowerEnemy.cs
Normal file
72
Assets/Scripts/ThrowerEnemy.cs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AI;
|
||||||
|
|
||||||
|
public class ThrowerEnemy : MonoBehaviour
|
||||||
|
{
|
||||||
|
public float hp;
|
||||||
|
public float hurtAmount;
|
||||||
|
public MeshRenderer MeshRenderer;
|
||||||
|
public Material def;
|
||||||
|
public Material hur;
|
||||||
|
public bool isInside;
|
||||||
|
|
||||||
|
public float playerDistance;
|
||||||
|
public GameObject GunBayonette;
|
||||||
|
|
||||||
|
private NavMeshAgent agent;
|
||||||
|
public Transform target;
|
||||||
|
|
||||||
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
MeshRenderer = GetComponent<MeshRenderer>();
|
||||||
|
agent = GetComponent<NavMeshAgent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
agent.SetDestination(target.position);
|
||||||
|
if (hp < 0)
|
||||||
|
{
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isInside && hp != 0)
|
||||||
|
MeshRenderer.material = def;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
void FixedUpdate()
|
||||||
|
{
|
||||||
|
playerDistance = Vector3.Distance(transform.position, target.position);
|
||||||
|
if (playerDistance < 25)
|
||||||
|
{
|
||||||
|
Instantiate(GunBayonette);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LateUpdate()
|
||||||
|
{
|
||||||
|
if (hp == 0)
|
||||||
|
hp -= 1;
|
||||||
|
isInside = false;
|
||||||
|
}
|
||||||
|
public void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
|
if (other.gameObject.tag == "Sword")
|
||||||
|
{
|
||||||
|
hp -= hurtAmount;
|
||||||
|
MeshRenderer.material = hur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void OnTriggerStay(Collider other)
|
||||||
|
{
|
||||||
|
if (other.gameObject.tag == "Sword")
|
||||||
|
isInside = true;
|
||||||
|
}
|
||||||
|
public void OnTriggerExit(Collider other)
|
||||||
|
{
|
||||||
|
if (other.gameObject.tag == "Sword" && hp != 0)
|
||||||
|
MeshRenderer.material = def;
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/ThrowerEnemy.cs.meta
Normal file
2
Assets/Scripts/ThrowerEnemy.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d43b0a839f0bf4971aa5f6099f6ea211
|
||||||
Reference in New Issue
Block a user