no message
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
using System.Collections;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public enum UnitState
|
||||
{
|
||||
Idle,
|
||||
Move,
|
||||
MoveToResource,
|
||||
Gather
|
||||
}
|
||||
|
||||
public class Unit : MonoBehaviour
|
||||
{
|
||||
@@ -7,6 +18,16 @@ public class Unit : MonoBehaviour
|
||||
public GameObject selectionVisual;
|
||||
private NavMeshAgent navAgent;
|
||||
private SelectionMarker selectionMarker;
|
||||
[Header("Stats")]
|
||||
public UnitState state;
|
||||
public int gatherAmount;
|
||||
public float gatherRate;
|
||||
private float lastGatherTime;
|
||||
private ResourceSource resource;
|
||||
//events
|
||||
public class StateChangeEvent : UnitEvent<UnitState> { }
|
||||
public StateChangeEvent onStateChange;
|
||||
public Player player;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
@@ -27,6 +48,24 @@ public class Unit : MonoBehaviour
|
||||
selectionMarker.DestroySelectionMarker();
|
||||
selectionMarker = null;
|
||||
}
|
||||
switch(state)
|
||||
{
|
||||
case UnitState.Move
|
||||
{
|
||||
MoveUpdate();
|
||||
break;
|
||||
}
|
||||
case UnitState.MoveToResource
|
||||
{
|
||||
MoveToResourceUpdate();
|
||||
break;
|
||||
}
|
||||
case UnitState.Gather
|
||||
{
|
||||
GatherUpdate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void ToggleSelectionVisual(bool selected)
|
||||
{
|
||||
@@ -43,4 +82,33 @@ public class Unit : MonoBehaviour
|
||||
navAgent.SetDestination(pos);
|
||||
selectionMarker = marker;
|
||||
}
|
||||
//move to a resource and begin to gather it
|
||||
public void GatherResource(ResourceSource resource, Vector3 pos)
|
||||
{
|
||||
|
||||
}
|
||||
void SetState(UnitState toState)
|
||||
{
|
||||
state = toState;
|
||||
//calling the event
|
||||
if(onStateChange != null)
|
||||
onStateChange.Invoke(state);
|
||||
if(toState == UnitState.Idle)
|
||||
{
|
||||
navAgent.isStopped = true;
|
||||
navAgent.ResetPath();
|
||||
}
|
||||
}
|
||||
void MoveUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
void MoveToResourceUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
void GatherUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user