Ratbots deal damage to the player upon contact
This commit is contained in:
@@ -3,7 +3,10 @@ using UnityEngine;
|
|||||||
public class Ratbot : MonoBehaviour
|
public class Ratbot : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float moveSpeed;
|
public float moveSpeed;
|
||||||
|
public float damageStrength;
|
||||||
|
public float damageTimeoutSeconds;
|
||||||
GameObject player;
|
GameObject player;
|
||||||
|
float lastDamageTime;
|
||||||
// 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
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
@@ -17,4 +20,11 @@ public class Ratbot : MonoBehaviour
|
|||||||
Vector2 direction = (player.transform.position - transform.position).normalized;
|
Vector2 direction = (player.transform.position - transform.position).normalized;
|
||||||
controller.linearVelocity = direction*moveSpeed;
|
controller.linearVelocity = direction*moveSpeed;
|
||||||
}
|
}
|
||||||
|
void OnCollisionStay2D(Collision2D collision) {
|
||||||
|
// Deal damage when colliding with the player on a 0.5 second cooldown
|
||||||
|
if (collision.gameObject.tag != "Player") return;
|
||||||
|
if (lastDamageTime > Time.fixedTime-damageTimeoutSeconds) return;
|
||||||
|
lastDamageTime = Time.fixedTime;
|
||||||
|
collision.gameObject.GetComponent<Teo>().health -= damageStrength;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ GameObject:
|
|||||||
- component: {fileID: 3449798187735636588}
|
- component: {fileID: 3449798187735636588}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Ratbot
|
m_Name: Ratbot
|
||||||
m_TagString: Untagged
|
m_TagString: Ratbot
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
@@ -103,6 +103,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
moveSpeed: 9.3
|
moveSpeed: 9.3
|
||||||
|
damageTimeoutSeconds: 0.5
|
||||||
--- !u!61 &8441426735084966298
|
--- !u!61 &8441426735084966298
|
||||||
BoxCollider2D:
|
BoxCollider2D:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
%TAG !u! tag:unity3d.com,2011:
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
--- !u!78 &1
|
--- !u!78 &1
|
||||||
TagManager:
|
TagManager:
|
||||||
serializedVersion: 2
|
serializedVersion: 3
|
||||||
tags: []
|
tags:
|
||||||
|
- Ratbot
|
||||||
layers:
|
layers:
|
||||||
- Default
|
- Default
|
||||||
- TransparentFX
|
- TransparentFX
|
||||||
@@ -41,3 +42,5 @@ TagManager:
|
|||||||
- name: Default
|
- name: Default
|
||||||
uniqueID: 0
|
uniqueID: 0
|
||||||
locked: 0
|
locked: 0
|
||||||
|
m_RenderingLayers:
|
||||||
|
- Default
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
- [x] Player that moves
|
- [x] Player that moves
|
||||||
- [x] Camera follows player
|
- [x] Camera follows player
|
||||||
- [x] Health
|
- [x] Health
|
||||||
- [ ] Enemy takes health when touches
|
- [x] Enemy takes health when touches
|
||||||
- [ ] Enemy health bar
|
- [ ] Enemy health bar
|
||||||
- [ ] Sword that points to mouse cursor
|
- [ ] Sword that points to mouse cursor
|
||||||
- [ ] Sword swings when click
|
- [ ] Sword swings when click
|
||||||
@@ -40,7 +40,6 @@
|
|||||||
- [ ] Detect when wave ends
|
- [ ] Detect when wave ends
|
||||||
- [ ] Activate new waves after powerup has been chosen by player
|
- [ ] Activate new waves after powerup has been chosen by player
|
||||||
|
|
||||||
|
|
||||||
### Enemy:
|
### Enemy:
|
||||||
- [x] All Enemies have simple pathfinding towards the player
|
- [x] All Enemies have simple pathfinding towards the player
|
||||||
- [ ] When enemy touches player - remove health (scaled with x amount of rounds)
|
- [ ] When enemy touches player - remove health (scaled with x amount of rounds)
|
||||||
|
|||||||
Reference in New Issue
Block a user