Health system for ratbots, can now stab ratbots
This commit is contained in:
@@ -5,7 +5,6 @@ public class GameState : MonoBehaviour
|
|||||||
public string state;
|
public string state;
|
||||||
public uint wave = 1;
|
public uint wave = 1;
|
||||||
public GameObject ratbot;
|
public GameObject ratbot;
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
NewWave();
|
NewWave();
|
||||||
}
|
}
|
||||||
@@ -30,6 +29,7 @@ public class GameState : MonoBehaviour
|
|||||||
for (uint _ = 0; _ < wave; _++) {
|
for (uint _ = 0; _ < wave; _++) {
|
||||||
GameObject newRatbot = Instantiate(ratbot);
|
GameObject newRatbot = Instantiate(ratbot);
|
||||||
newRatbot.GetComponent<Ratbot>().damageStrength = 5+wave*5;
|
newRatbot.GetComponent<Ratbot>().damageStrength = 5+wave*5;
|
||||||
|
newRatbot.GetComponent<Ratbot>().health = 5+wave*2;
|
||||||
}
|
}
|
||||||
wave++;
|
wave++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ public class Ratbot : MonoBehaviour
|
|||||||
public float moveSpeed;
|
public float moveSpeed;
|
||||||
public float damageStrength;
|
public float damageStrength;
|
||||||
public float damageTimeoutSeconds;
|
public float damageTimeoutSeconds;
|
||||||
|
public float health = 10;
|
||||||
float lastDamageTime;
|
float lastDamageTime;
|
||||||
GameState gameState;
|
GameState gameState;
|
||||||
GameObject player;
|
GameObject player;
|
||||||
@@ -29,4 +30,10 @@ public class Ratbot : MonoBehaviour
|
|||||||
lastDamageTime = Time.fixedTime;
|
lastDamageTime = Time.fixedTime;
|
||||||
collision.gameObject.GetComponent<Teo>().health -= damageStrength;
|
collision.gameObject.GetComponent<Teo>().health -= damageStrength;
|
||||||
}
|
}
|
||||||
|
public void Damage(float hurtyAmount) {
|
||||||
|
health -= hurtyAmount;
|
||||||
|
if (health <= 0) {
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -316,7 +316,10 @@ PrefabInstance:
|
|||||||
m_RemovedComponents:
|
m_RemovedComponents:
|
||||||
- {fileID: 0}
|
- {fileID: 0}
|
||||||
m_RemovedGameObjects: []
|
m_RemovedGameObjects: []
|
||||||
m_AddedGameObjects: []
|
m_AddedGameObjects:
|
||||||
|
- targetCorrespondingSourceObject: {fileID: 4154134366646162009, guid: e05928a0d673caf999d31b31b994a112, type: 3}
|
||||||
|
insertIndex: -1
|
||||||
|
addedObject: {fileID: 1873397571}
|
||||||
m_AddedComponents:
|
m_AddedComponents:
|
||||||
- targetCorrespondingSourceObject: {fileID: 8669953498445216587, guid: e05928a0d673caf999d31b31b994a112, type: 3}
|
- targetCorrespondingSourceObject: {fileID: 8669953498445216587, guid: e05928a0d673caf999d31b31b994a112, type: 3}
|
||||||
insertIndex: 1
|
insertIndex: 1
|
||||||
@@ -546,6 +549,11 @@ Skybox:
|
|||||||
m_GameObject: {fileID: 977303806}
|
m_GameObject: {fileID: 977303806}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_CustomSkybox: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
m_CustomSkybox: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
|
--- !u!4 &1246075822 stripped
|
||||||
|
Transform:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 4154134366646162009, guid: e05928a0d673caf999d31b31b994a112, type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 309882168}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
--- !u!1 &1394869898
|
--- !u!1 &1394869898
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -695,6 +703,106 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 07e7096bcd8103c3faadeefc30c8a2f4, type: 3}
|
m_Script: {fileID: 11500000, guid: 07e7096bcd8103c3faadeefc30c8a2f4, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!1 &1873397570
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1873397571}
|
||||||
|
- component: {fileID: 1873397573}
|
||||||
|
- component: {fileID: 1873397572}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: sword_0
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &1873397571
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1873397570}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 2.001004, y: 2.001004, z: 2.001004}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1246075822}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &1873397572
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1873397570}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 12e2e0dada30fe215be589422e1df9b7, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!212 &1873397573
|
||||||
|
SpriteRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1873397570}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_CastShadows: 0
|
||||||
|
m_ReceiveShadows: 0
|
||||||
|
m_DynamicOccludee: 1
|
||||||
|
m_StaticShadowCaster: 0
|
||||||
|
m_MotionVectors: 1
|
||||||
|
m_LightProbeUsage: 1
|
||||||
|
m_ReflectionProbeUsage: 1
|
||||||
|
m_RayTracingMode: 0
|
||||||
|
m_RayTraceProcedural: 0
|
||||||
|
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||||
|
m_RayTracingAccelStructBuildFlags: 1
|
||||||
|
m_SmallMeshCulling: 1
|
||||||
|
m_RenderingLayerMask: 1
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 0
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 1
|
||||||
|
m_Sprite: {fileID: -3753825769889500098, guid: 9216a0f04ef201ab08cf158320feac60, type: 3}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_FlipX: 0
|
||||||
|
m_FlipY: 0
|
||||||
|
m_DrawMode: 0
|
||||||
|
m_Size: {x: 4.82, y: 4.82}
|
||||||
|
m_AdaptiveModeThreshold: 0.5
|
||||||
|
m_SpriteTileMode: 0
|
||||||
|
m_WasSpriteAssigned: 1
|
||||||
|
m_MaskInteraction: 0
|
||||||
|
m_SpriteSortPoint: 0
|
||||||
--- !u!1660057539 &9223372036854775807
|
--- !u!1660057539 &9223372036854775807
|
||||||
SceneRoots:
|
SceneRoots:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ public class Teo : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public float health = 100;
|
public float health = 100;
|
||||||
public float moveSpeed = 10;
|
public float moveSpeed = 10;
|
||||||
|
public float swingRange = 3;
|
||||||
|
public float damageStrength = 10;
|
||||||
Rigidbody2D controller;
|
Rigidbody2D controller;
|
||||||
GameState gameState;
|
GameState gameState;
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||||
@@ -18,5 +20,21 @@ public class Teo : MonoBehaviour
|
|||||||
Input.GetAxis("Horizontal"),
|
Input.GetAxis("Horizontal"),
|
||||||
Input.GetAxis("Vertical")
|
Input.GetAxis("Vertical")
|
||||||
).normalized * moveSpeed;
|
).normalized * moveSpeed;
|
||||||
|
|
||||||
|
if (Input.GetMouseButtonDown(0)) {
|
||||||
|
RaycastHit2D[] hits = Physics2D.CircleCastAll(
|
||||||
|
transform.position,
|
||||||
|
swingRange,
|
||||||
|
new Vector2(
|
||||||
|
Screen.width/2 - Input.mousePosition.x,
|
||||||
|
Screen.height/2 - Input.mousePosition.y
|
||||||
|
)
|
||||||
|
);
|
||||||
|
foreach (RaycastHit2D hit in hits) {
|
||||||
|
Ratbot ratbot = hit.collider.GetComponent<Ratbot>();
|
||||||
|
if (ratbot == null) continue;
|
||||||
|
ratbot.Damage(damageStrength);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user