WUT_Computer_Science/The project/Assets/Scripts/Soldier.cs
Gabriel Ksawery Skowron-Rodriguez 50882e48db Added basic Squad logic
+ Squad
++ aggregates soldiers
++ orders are passed to soldiers (one order per tick)
+- for now debug functions to simulate player inputting of a movement order
2022-05-16 14:21:52 +02:00

59 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Soldier : MonoBehaviour
{
private const string enemyTag = "Enemy";
private const float healthPoints = 1;
private const float rangeAttack = 1;
private const float rangeView = 1;
private const float damageAttack = 1;
private const float speedAttack = 1;
// Start is called before the first frame update
void Start(){
//InvokeRepeating("UpdateTarget", 0f, 0.5f);
// Call UpdateTarget method at the begining of the Start()
// and repeat every 0.5 second
}
void UpdateTarget ()
{
// Enemies are the game objects tagged with the "Enemy"
GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyTag);
// We have not found enemy yet so the distance to enemy is "infinite"
float shortestDistance = Mathf.Infinity;
GameObject nearestEnemy = null;
foreach ( GameObject enemy in enemies)
{
// Go through each enemy existing
// Calculate distance to this enemy
float distanceToEnemy = Vector3.Distance(transform.position, enemy.transform.position);
if (distanceToEnemy < shortestDistance)
{
shortestDistance = distanceToEnemy;
nearestEnemy = enemy;
}
}
if (nearestEnemy != null && shortestDistance <= rangeAttack)
{
//COMMENTED OUT-PICK REJECT THIS CONFLICT IF IT EVER HAPPENStarget = nearestEnemey.transform;
}
}
// Update is called once per frame
void Update()
{
//COMMENTED OUT-PICK REJECT THIS CONFLICT IF IT EVER HAPPENS if (target == null) return;
}
/* https://www.youtube.com/watch?v=QKhn2kl9_8I 08:54 Soldier attack
void OnDrawGizmosSelected ()
{
}
*/
}