add: EyeEnemy proper functionality
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyBulletProjectile : MonoBehaviour
|
||||
{
|
||||
public float speed = 1f;
|
||||
public float damage = 20f;
|
||||
public float timeToLive = 5f;
|
||||
|
||||
float currentTime = 0;
|
||||
|
||||
Rigidbody rb;
|
||||
|
||||
void Start() {
|
||||
rb = GetComponent<Rigidbody>();
|
||||
rb.linearVelocity = transform.forward * speed;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
currentTime += Time.deltaTime;
|
||||
if (currentTime >= timeToLive) Destroy(gameObject);
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider other) {
|
||||
if (other.gameObject.CompareTag("Player")) {
|
||||
Player player = other.GetComponent<Player>();
|
||||
player.DealDamage(damage);
|
||||
}
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d7536bbb5cbf394b8ec742b12cb0b87
|
||||
@@ -2,13 +2,31 @@ using UnityEngine;
|
||||
|
||||
public class EyeEnemy : Enemy
|
||||
{
|
||||
public float _hp = 100;
|
||||
public GameObject projectilePrefab;
|
||||
public Transform projectileSpawnPosition;
|
||||
public float attackRange = 10f;
|
||||
public float fireRate = 1f;
|
||||
public float offsetDistance = 1f;
|
||||
|
||||
[SerializeField] float currentDelay = 0;
|
||||
|
||||
[SerializeField] Player target;
|
||||
|
||||
void Start() {
|
||||
hp = _hp;
|
||||
target = FindFirstObjectByType<Player>();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
|
||||
if (fireRate != 0) currentDelay = Mathf.Clamp(currentDelay += Time.deltaTime, 0, 1 / fireRate);
|
||||
Vector3 offset = (target.transform.position - projectileSpawnPosition.position).normalized * offsetDistance;
|
||||
bool doShoot = false;
|
||||
if (Physics.Raycast(projectileSpawnPosition.position + offset, offset, out RaycastHit hit, attackRange)) {
|
||||
if (hit.transform.CompareTag("Player")) doShoot = true;
|
||||
}
|
||||
if (doShoot && (fireRate == 0 || currentDelay >= 1 / fireRate)) {
|
||||
GameObject projectile = Instantiate(projectilePrefab, projectileSpawnPosition.position + offset, transform.rotation);
|
||||
projectile.transform.LookAt(target.transform);
|
||||
currentDelay = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using UnityEngine.SceneManagement;
|
||||
public class DeployController : MonoBehaviour
|
||||
{
|
||||
public void Start() {
|
||||
GameController.SetCursorState(true);
|
||||
GameController.SetCursorState(false);
|
||||
}
|
||||
|
||||
public void Deploy(string sceneName) {
|
||||
|
||||
@@ -7,9 +7,11 @@ public class GroundDetector : MonoBehaviour
|
||||
|
||||
public void OnTriggerEnter(Collider other) {
|
||||
if ((1 << other.gameObject.layer & groundMask) != 0) onGround = true;
|
||||
// onGround = true;
|
||||
}
|
||||
void OnTriggerStay(Collider other) { OnTriggerEnter(other); }
|
||||
void OnTriggerExit(Collider other) {
|
||||
if ((1 << other.gameObject.layer & groundMask) != 0) onGround = false;
|
||||
// onGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user