Hopefully there's okay comments on things now
This commit is contained in:
@@ -24,8 +24,10 @@ public class GameState : MonoBehaviour
|
|||||||
|
|
||||||
}
|
}
|
||||||
public void NewWave() {
|
public void NewWave() {
|
||||||
|
// Spawn ratbots around the player
|
||||||
|
// Amount, health, and damage scale with waves
|
||||||
state = "WAVE";
|
state = "WAVE";
|
||||||
Vector3 playerPosition = GameObject.FindGameObjectWithTag("Player").GetComponent<Teo>().transform.position;
|
Vector3 playerPosition = GameObject.FindGameObjectWithTag("Player").transform.position;
|
||||||
for (uint _ = 0; _ < wave; _++) {
|
for (uint _ = 0; _ < wave; _++) {
|
||||||
GameObject newRatbot = Instantiate(
|
GameObject newRatbot = Instantiate(
|
||||||
ratbot,
|
ratbot,
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ MonoBehaviour:
|
|||||||
moveSpeed: 15
|
moveSpeed: 15
|
||||||
swingRange: 2
|
swingRange: 2
|
||||||
damageStrength: 10
|
damageStrength: 10
|
||||||
|
attackCooldownSeconds: 2
|
||||||
--- !u!50 &-4152331571693237436
|
--- !u!50 &-4152331571693237436
|
||||||
Rigidbody2D:
|
Rigidbody2D:
|
||||||
serializedVersion: 5
|
serializedVersion: 5
|
||||||
|
|||||||
@@ -9,20 +9,20 @@ public class Ratbot : MonoBehaviour
|
|||||||
float lastDamageTime;
|
float lastDamageTime;
|
||||||
GameState gameState;
|
GameState gameState;
|
||||||
GameObject player;
|
GameObject player;
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
||||||
void Start()
|
void Start() {
|
||||||
{
|
// Set gameState and player objects
|
||||||
player = GameObject.FindGameObjectWithTag("Player");
|
player = GameObject.FindGameObjectWithTag("Player");
|
||||||
gameState = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameState>();
|
gameState = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameState>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
void Update() {
|
||||||
void Update()
|
// Constantly move towards player
|
||||||
{
|
|
||||||
Rigidbody2D controller = GetComponent<Rigidbody2D>();
|
Rigidbody2D controller = GetComponent<Rigidbody2D>();
|
||||||
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) {
|
void OnCollisionStay2D(Collision2D collision) {
|
||||||
// Deal damage when colliding with the player on a 0.5 second cooldown
|
// Deal damage when colliding with the player on a 0.5 second cooldown
|
||||||
if (collision.gameObject.tag != "Player") return;
|
if (collision.gameObject.tag != "Player") return;
|
||||||
@@ -30,6 +30,8 @@ public class Ratbot : MonoBehaviour
|
|||||||
lastDamageTime = Time.fixedTime;
|
lastDamageTime = Time.fixedTime;
|
||||||
collision.gameObject.GetComponent<Teo>().health -= damageStrength;
|
collision.gameObject.GetComponent<Teo>().health -= damageStrength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Die if health below zero
|
||||||
public void Damage(float hurtyAmount) {
|
public void Damage(float hurtyAmount) {
|
||||||
health -= hurtyAmount;
|
health -= hurtyAmount;
|
||||||
if (health <= 0) {
|
if (health <= 0) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public class Sword : MonoBehaviour
|
|||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
// Point sword towards mouse cursor with garbage trig
|
||||||
transform.rotation = Quaternion.Euler(
|
transform.rotation = Quaternion.Euler(
|
||||||
new Vector3 (0, 0, Mathf.Atan2(
|
new Vector3 (0, 0, Mathf.Atan2(
|
||||||
Screen.height/2 - Input.mousePosition.y,
|
Screen.height/2 - Input.mousePosition.y,
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ public class Teo : MonoBehaviour
|
|||||||
public float moveSpeed = 10;
|
public float moveSpeed = 10;
|
||||||
public float swingRange = 3;
|
public float swingRange = 3;
|
||||||
public float damageStrength = 10;
|
public float damageStrength = 10;
|
||||||
|
public float attackCooldownSeconds = 2;
|
||||||
Rigidbody2D controller;
|
Rigidbody2D controller;
|
||||||
GameState gameState;
|
GameState gameState;
|
||||||
|
float lastAttackTime;
|
||||||
// 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() {
|
||||||
controller = GetComponent<Rigidbody2D>();
|
controller = GetComponent<Rigidbody2D>();
|
||||||
@@ -16,12 +18,15 @@ public class Teo : MonoBehaviour
|
|||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update() {
|
void Update() {
|
||||||
|
// Move player
|
||||||
controller.linearVelocity = new Vector2 (
|
controller.linearVelocity = new Vector2 (
|
||||||
Input.GetAxis("Horizontal"),
|
Input.GetAxis("Horizontal"),
|
||||||
Input.GetAxis("Vertical")
|
Input.GetAxis("Vertical")
|
||||||
).normalized * moveSpeed;
|
).normalized * moveSpeed;
|
||||||
|
|
||||||
if (Input.GetMouseButtonDown(0)) {
|
// Attack on click if not on cooldown
|
||||||
|
if (Input.GetMouseButtonDown(0) && Time.fixedTime > lastAttackTime + attackCooldownSeconds) {
|
||||||
|
// Get all objects in range in the direction of cursor
|
||||||
RaycastHit2D[] hits = Physics2D.CircleCastAll(
|
RaycastHit2D[] hits = Physics2D.CircleCastAll(
|
||||||
transform.position,
|
transform.position,
|
||||||
swingRange,
|
swingRange,
|
||||||
@@ -30,6 +35,7 @@ public class Teo : MonoBehaviour
|
|||||||
Screen.height/2 - Input.mousePosition.y
|
Screen.height/2 - Input.mousePosition.y
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
// Damage all ratbots in scanned area
|
||||||
foreach (RaycastHit2D hit in hits) {
|
foreach (RaycastHit2D hit in hits) {
|
||||||
Ratbot ratbot = hit.collider.GetComponent<Ratbot>();
|
Ratbot ratbot = hit.collider.GetComponent<Ratbot>();
|
||||||
if (ratbot == null) continue;
|
if (ratbot == null) continue;
|
||||||
|
|||||||
@@ -96,6 +96,19 @@ TextureImporter:
|
|||||||
ignorePlatformSupport: 0
|
ignorePlatformSupport: 0
|
||||||
androidETC2FallbackOverride: 0
|
androidETC2FallbackOverride: 0
|
||||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 4
|
||||||
|
buildTarget: WebGL
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
ignorePlatformSupport: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
spriteSheet:
|
spriteSheet:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
sprites:
|
sprites:
|
||||||
@@ -134,7 +147,8 @@ TextureImporter:
|
|||||||
secondaryTextures: []
|
secondaryTextures: []
|
||||||
spriteCustomMetadata:
|
spriteCustomMetadata:
|
||||||
entries: []
|
entries: []
|
||||||
nameFileIdTable: {}
|
nameFileIdTable:
|
||||||
|
teoCropped_0: 4084514856309348668
|
||||||
mipmapLimitGroupName:
|
mipmapLimitGroupName:
|
||||||
pSDRemoveMatte: 0
|
pSDRemoveMatte: 0
|
||||||
userData:
|
userData:
|
||||||
|
|||||||
Reference in New Issue
Block a user