Skip to content
Snippets Groups Projects
Commit 30d73cd8 authored by Adam Elfawal's avatar Adam Elfawal
Browse files

Added Object health script

parent 6c8b23a2
No related branches found
No related tags found
No related merge requests found
......@@ -203,6 +203,7 @@ GameObject:
- component: {fileID: 374944065}
- component: {fileID: 374944064}
- component: {fileID: 374944068}
- component: {fileID: 374944069}
m_Layer: 7
m_Name: Obstacle_1
m_TagString: Untagged
......@@ -308,7 +309,22 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b27a0bea99c8c21498b314d21a51a657, type: 3}
m_Name:
m_EditorClassIdentifier:
mat: {fileID: 0}
generateBasicMaterial: 1
--- !u!114 &374944069
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 374944063}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b1b9e4b57b26b0842a2fbe8cdceb0444, type: 3}
m_Name:
m_EditorClassIdentifier:
health: 1
destroyMode: 2
stateChangePrefab: {fileID: 0}
--- !u!1 &468589951
GameObject:
m_ObjectHideFlags: 0
......@@ -836,7 +852,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: ccadac2e5fe8b0d4b8feaac68da20995, type: 3}
m_Name:
m_EditorClassIdentifier:
cameraTrans: {fileID: 963194228}
playerTrans: {fileID: 1107822519}
--- !u!114 &963194230
MonoBehaviour:
......@@ -1743,7 +1758,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b27a0bea99c8c21498b314d21a51a657, type: 3}
m_Name:
m_EditorClassIdentifier:
mat: {fileID: 0}
generateBasicMaterial: 0
--- !u!65 &1594897153
BoxCollider:
m_ObjectHideFlags: 0
......@@ -1933,7 +1948,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b27a0bea99c8c21498b314d21a51a657, type: 3}
m_Name:
m_EditorClassIdentifier:
mat: {fileID: 0}
generateBasicMaterial: 0
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
......
......@@ -5,6 +5,8 @@
public class Dithering : MonoBehaviour
{
private Material mat;
[Header("Check this is you have a basic color material")]
public bool generateBasicMaterial = false;
// Start is called before the first frame update
void Start()
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectHealth : MonoBehaviour
{
[Header("Health of the object")]
public int health = 1;
[Header("Select How the object will change (use none if it doesn't)")]
public DestroyMode destroyMode = DestroyMode.None;
[Header("For objects like the water cooler or vent, put the object prefab here")]
public GameObject stateChangePrefab;
/// <summary>
/// Meant to be called by Cats code that's dealing with launching the items
/// </summary>
/// <param name="damage">The amount of damage the object is taking</param>
public void Damage(int damage)
{
health -= damage;
if(health <= 0)
{
if (destroyMode == DestroyMode.Shatter)
{
Shatter();
}
else if(destroyMode == DestroyMode.StateChange)
{
StateChange();
}
else
{
//Maybe we want a cracked material on it if its damaged but won't break, we would do that here
}
}
}
/// <summary>
/// Object will shatter into like a billion pieces (estimation)
/// </summary>
private void Shatter()
{
//Make Object shatter here
}
/// <summary>
/// This is for things like a water cooler or vent where when you hit it it changes into something different that has alternative functionaility
/// </summary>
private void StateChange()
{
Instantiate(stateChangePrefab, gameObject.transform.position, Quaternion.identity);
}
}
public enum DestroyMode
{
Shatter,
StateChange,
None
}
fileFormatVersion: 2
guid: b1b9e4b57b26b0842a2fbe8cdceb0444
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment