Onto lesson 2
This commit is contained in:
@@ -1,22 +1,46 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class Unit : MonoBehaviour
|
||||
{
|
||||
[Header("Components")]
|
||||
public GameObject selectionVisual;
|
||||
private NavMeshAgent navAgent;
|
||||
private SelectionMarker selectionMarker;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
//get the components
|
||||
navAgent = GetComponent<NavMeshAgent>();
|
||||
}
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
if (selectionMarker != null && !navAgent.pathPending && navAgent.remainingDistance <= navAgent.stoppingDistance)
|
||||
{
|
||||
selectionMarker.DestroySelectionMarker();
|
||||
selectionMarker = null;
|
||||
}
|
||||
}
|
||||
public void ToggleSelectionVisual(bool selected)
|
||||
{
|
||||
selectionVisual.SetActive(selected);
|
||||
}
|
||||
public void MoveToPosition(Vector3 pos, SelectionMarker marker = null)
|
||||
{
|
||||
if (selectionMarker != null)
|
||||
{
|
||||
selectionMarker.DestroySelectionMarker();
|
||||
selectionMarker = null;
|
||||
}
|
||||
navAgent.isStopped = false;
|
||||
navAgent.SetDestination(pos);
|
||||
selectionMarker = marker;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user