We got fast fuckers now
This commit is contained in:
30
Assets/Scripts C#/Ratbots/FastFucker.cs
Normal file
30
Assets/Scripts C#/Ratbots/FastFucker.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class FastFucker : Ratbot
|
||||
{
|
||||
bool attack = true;
|
||||
void Update() {
|
||||
if (attack)
|
||||
MoveTowardsPlayer(moveSpeed*3);
|
||||
else
|
||||
MoveAwayFromPlayer(moveSpeed);
|
||||
}
|
||||
void MoveAwayFromPlayer(float speed) {
|
||||
controller.AddRelativeForce(
|
||||
(transform.position - player.transform.position)
|
||||
.normalized
|
||||
*speed
|
||||
*Time.deltaTime
|
||||
);
|
||||
}
|
||||
new void OnCollisionStay2D (Collision2D collision) {
|
||||
base.OnCollisionStay2D(collision);
|
||||
StartCoroutine("RunAway");
|
||||
}
|
||||
IEnumerator RunAway() {
|
||||
attack = false;
|
||||
yield return new WaitForSeconds (1F);
|
||||
attack = true;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts C#/Ratbots/FastFucker.cs.meta
Normal file
2
Assets/Scripts C#/Ratbots/FastFucker.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07603fdf7ab38f05493e2a22ef5cae06
|
||||
@@ -10,28 +10,33 @@ public class Ratbot : MonoBehaviour
|
||||
|
||||
public static GameState gameState;
|
||||
public static GameObject player;
|
||||
public Rigidbody2D controller;
|
||||
|
||||
void Start() {
|
||||
SetVars();
|
||||
}
|
||||
|
||||
public void SetVars() {
|
||||
controller = GetComponent<Rigidbody2D>();
|
||||
// Set gameState and player objects
|
||||
player = GameObject.FindGameObjectWithTag("Player");
|
||||
gameState = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameState>();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
MoveTowardsPlayer();
|
||||
MoveTowardsPlayer(moveSpeed);
|
||||
}
|
||||
|
||||
public void MoveTowardsPlayer() {
|
||||
Rigidbody2D controller = GetComponent<Rigidbody2D>();
|
||||
Vector2 direction = (player.transform.position - transform.position).normalized;
|
||||
controller.AddRelativeForce(direction*moveSpeed*Time.deltaTime);
|
||||
public void MoveTowardsPlayer(float speed) {
|
||||
controller.AddRelativeForce(
|
||||
(player.transform.position - transform.position)
|
||||
.normalized
|
||||
*speed
|
||||
*Time.deltaTime
|
||||
);
|
||||
}
|
||||
|
||||
void OnCollisionStay2D(Collision2D collision) {
|
||||
public virtual 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;
|
||||
|
||||
Reference in New Issue
Block a user