Zombie drop body parts

This commit is contained in:
Kotrba Filip 2020-02-01 10:12:47 +01:00
parent e72b3e2092
commit 39b3f8277d
4 changed files with 92 additions and 178 deletions

View File

@ -121,90 +121,6 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 23800000, guid: 210c0a45ca7dddb429c704640ac83479, type: 2}
--- !u!1001 &134370123
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalPosition.y
value: 1.35
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalPosition.z
value: 2.1
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalRotation.x
value: -0.7071068
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalRotation.w
value: 0.7071067
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_RootOrder
value: 3
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalScale.x
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalScale.y
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_LocalScale.z
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: -927199367670048503, guid: 187e7593e510e0445b95707cb14176d6,
type: 3}
propertyPath: m_Name
value: radio
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 187e7593e510e0445b95707cb14176d6, type: 3}
--- !u!1 &597793628
GameObject:
m_ObjectHideFlags: 0
@ -327,6 +243,12 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &709589677 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 6771538179627932786, guid: b4e392e2cdb417b4c8bdf8e683bceb9b,
type: 3}
m_PrefabInstance: {fileID: 3163490711718144037}
m_PrefabAsset: {fileID: 0}
--- !u!1 &827899963 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 5859379536716062794, guid: 5322794fa1699704b8e50a14cef106b1,
@ -401,7 +323,7 @@ PrefabInstance:
- target: {fileID: -4216859302048453862, guid: a20f14621725df742ad2c1028ff4f453,
type: 3}
propertyPath: m_RootOrder
value: 4
value: 2
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: a20f14621725df742ad2c1028ff4f453,
type: 3}
@ -438,6 +360,11 @@ PrefabInstance:
propertyPath: m_Name
value: lanterd
objectReference: {fileID: 0}
- target: {fileID: -927199367670048503, guid: a20f14621725df742ad2c1028ff4f453,
type: 3}
propertyPath: m_Layer
value: 4
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: a20f14621725df742ad2c1028ff4f453, type: 3}
--- !u!1 &1129927357
@ -504,7 +431,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 9
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1272265849
GameObject:
@ -536,90 +463,6 @@ Transform:
m_Father: {fileID: 827899965}
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1576294198
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalRotation.x
value: -0.7071068
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalRotation.w
value: 0.7071067
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalScale.x
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalScale.y
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_LocalScale.z
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: -927199367670048503, guid: 01af5eaeb15b4cf469b3d5c80775fd22,
type: 3}
propertyPath: m_Name
value: table
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 01af5eaeb15b4cf469b3d5c80775fd22, type: 3}
--- !u!1 &1753935063
GameObject:
m_ObjectHideFlags: 0
@ -694,7 +537,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1838907804
PrefabInstance:
@ -741,7 +584,7 @@ PrefabInstance:
- target: {fileID: -4216859302048453862, guid: 18a9d16f45ee7544190e7437a99f97de,
type: 3}
propertyPath: m_RootOrder
value: 2
value: 1
objectReference: {fileID: 0}
- target: {fileID: -4216859302048453862, guid: 18a9d16f45ee7544190e7437a99f97de,
type: 3}
@ -800,6 +643,12 @@ MonoBehaviour:
m_EditorClassIdentifier:
blockType: 0
health: 100
--- !u!1 &2041862263 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 451344880335272152, guid: b4e392e2cdb417b4c8bdf8e683bceb9b,
type: 3}
m_PrefabInstance: {fileID: 3163490711718144037}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &3163490711718144037
PrefabInstance:
m_ObjectHideFlags: 0
@ -850,7 +699,7 @@ PrefabInstance:
- target: {fileID: 5004747464968674621, guid: b4e392e2cdb417b4c8bdf8e683bceb9b,
type: 3}
propertyPath: m_RootOrder
value: 7
value: 5
objectReference: {fileID: 0}
- target: {fileID: 5004747464968674621, guid: b4e392e2cdb417b4c8bdf8e683bceb9b,
type: 3}
@ -867,6 +716,26 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5433357422100294214, guid: b4e392e2cdb417b4c8bdf8e683bceb9b,
type: 3}
propertyPath: bodyParts.Array.size
value: 2
objectReference: {fileID: 0}
- target: {fileID: 5433357422100294214, guid: b4e392e2cdb417b4c8bdf8e683bceb9b,
type: 3}
propertyPath: bodyParts.Array.data[0]
value:
objectReference: {fileID: 2041862263}
- target: {fileID: 5433357422100294214, guid: b4e392e2cdb417b4c8bdf8e683bceb9b,
type: 3}
propertyPath: bodyParts.Array.data[1]
value:
objectReference: {fileID: 709589677}
- target: {fileID: 5433357422100294214, guid: b4e392e2cdb417b4c8bdf8e683bceb9b,
type: 3}
propertyPath: bodyParts.Array.data[2]
value:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: b4e392e2cdb417b4c8bdf8e683bceb9b, type: 3}
--- !u!1001 &6179705720582673448
@ -1094,7 +963,7 @@ PrefabInstance:
- target: {fileID: 7425287328957043289, guid: 5322794fa1699704b8e50a14cef106b1,
type: 3}
propertyPath: m_RootOrder
value: 5
value: 3
objectReference: {fileID: 0}
- target: {fileID: 7425287328957043289, guid: 5322794fa1699704b8e50a14cef106b1,
type: 3}
@ -1198,7 +1067,7 @@ PrefabInstance:
- target: {fileID: 7985979212931499549, guid: 204c7411afdd01a478b1a1e25607d50c,
type: 3}
propertyPath: m_RootOrder
value: 6
value: 4
objectReference: {fileID: 0}
- target: {fileID: 7985979212931499549, guid: 204c7411afdd01a478b1a1e25607d50c,
type: 3}

View File

@ -6,12 +6,15 @@ using UnityEngine.AI;
public class EnemyManager : MonoBehaviour
{
public float health = 100;
public float actualHealth;
private NavMeshAgent navMeshAgent;
private PlayerManager player;
public List<GameObject> bodyParts = new List<GameObject>();
// Start is called before the first frame update
void Start()
{
actualHealth = health;
player = FindObjectOfType<PlayerManager>();
navMeshAgent = GetComponent<NavMeshAgent>();
}
@ -20,9 +23,32 @@ public class EnemyManager : MonoBehaviour
void Update()
{
navMeshAgent.SetDestination(player.transform.position);
if (health <= 0)
DropBodyPart();
if (actualHealth <= 0)
{
Destroy(this.gameObject);
if (bodyParts.Count > 0) {
foreach (GameObject bodyPart in bodyParts)
{
Destroy(bodyPart, 3);
}
}
navMeshAgent.isStopped = true;
navMeshAgent.enabled = false;
gameObject.AddComponent<Rigidbody>();
Rigidbody rigidBodyEnemy = gameObject.GetComponent<Rigidbody>() as Rigidbody;
rigidBodyEnemy.velocity = -gameObject.transform.forward;
rigidBodyEnemy.mass = 50;
Destroy(this.gameObject, 3);
}
}
void FixedUpdate()
{
if (actualHealth > 0)
{
Vector3 _dir = player.transform.position - transform.position;
_dir.Normalize();
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(_dir), 5 * Time.deltaTime);
}
}
@ -30,7 +56,26 @@ public class EnemyManager : MonoBehaviour
{
WeaponManager weaponManager = player.weaponList[player.selectedWeapon].GetComponent<WeaponManager>();
if (weaponManager != null) {
health -= weaponManager.damage;
actualHealth -= weaponManager.damage;
}
}
void DropBodyPart()
{
if (bodyParts.Count > 0)
{
float number = health / (bodyParts.Count + 1);
for (int i = 0; i < bodyParts.Count; i++)
{
if ((health - actualHealth) / number > i)
{
bodyParts[i].transform.parent = null;
bodyParts[i].AddComponent<Rigidbody>();
Rigidbody rigidBodyEnemy = bodyParts[i].GetComponent<Rigidbody>() as Rigidbody;
bodyParts[i].AddComponent<BoxCollider>();
rigidBodyEnemy.mass = 10;
}
}
}
}