gegner berabietet
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyShooter : MonoBehaviour
|
||||
{
|
||||
public float shootRange = 25f;
|
||||
public float shootDelay = 1f;
|
||||
public int damage = 10;
|
||||
|
||||
private PlayerHealth player;
|
||||
private float nextShotTime;
|
||||
|
||||
void Start()
|
||||
{
|
||||
player = FindFirstObjectByType<PlayerHealth>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (PauseMenu.GameIsPaused || player == null) return;
|
||||
|
||||
Vector3 direction = player.transform.position - transform.position;
|
||||
if (direction.magnitude > shootRange) return;
|
||||
|
||||
direction.y = 0f;
|
||||
if (direction != Vector3.zero)
|
||||
transform.rotation = Quaternion.LookRotation(direction);
|
||||
|
||||
if (Time.time >= nextShotTime && CanSeePlayer())
|
||||
{
|
||||
player.TakeDamage(damage);
|
||||
nextShotTime = Time.time + shootDelay;
|
||||
}
|
||||
}
|
||||
|
||||
bool CanSeePlayer()
|
||||
{
|
||||
Vector3 start = transform.position + Vector3.up;
|
||||
Vector3 target = player.transform.position + Vector3.up;
|
||||
Vector3 direction = target - start;
|
||||
|
||||
if (Physics.Raycast(start, direction.normalized, out RaycastHit hit, shootRange))
|
||||
return hit.collider.GetComponentInParent<PlayerHealth>() != null;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29f907e38ca44e3495ce692733ada681
|
||||
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class HostageRescue : MonoBehaviour
|
||||
{
|
||||
public float rescueDistance = 3f;
|
||||
public float escapeDistance = 15f;
|
||||
public float runSpeed = 5f;
|
||||
|
||||
private Transform player;
|
||||
private bool rescued;
|
||||
private Vector3 escapeDirection;
|
||||
private Vector3 startPosition;
|
||||
|
||||
void Start()
|
||||
{
|
||||
PlayerHealth playerHealth = FindFirstObjectByType<PlayerHealth>();
|
||||
if (playerHealth != null) player = playerHealth.transform;
|
||||
|
||||
startPosition = transform.position;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (PauseMenu.GameIsPaused || player == null) return;
|
||||
|
||||
if (rescued)
|
||||
{
|
||||
transform.position += escapeDirection * runSpeed * Time.deltaTime;
|
||||
if (Vector3.Distance(startPosition, transform.position) >= escapeDistance)
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Vector3.Distance(transform.position, player.position) <= rescueDistance &&
|
||||
Input.GetKeyDown(KeyCode.E))
|
||||
{
|
||||
RunAway();
|
||||
}
|
||||
}
|
||||
|
||||
void RunAway()
|
||||
{
|
||||
rescued = true;
|
||||
startPosition = transform.position;
|
||||
escapeDirection = (transform.position - player.position).normalized;
|
||||
escapeDirection.y = 0f;
|
||||
transform.rotation = Quaternion.LookRotation(escapeDirection);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62ea7866e4d846e2b5d207c6a3ec8afa
|
||||
Reference in New Issue
Block a user