35 lines
861 B
C#
35 lines
861 B
C#
using Code.Base;
|
|
using UnityEngine;
|
|
|
|
namespace Code.Lab3
|
|
{
|
|
public class Face : Align
|
|
{
|
|
protected GameObject TargetAux;
|
|
|
|
public override void Awake()
|
|
{
|
|
base.Awake();
|
|
TargetAux = target;
|
|
target = new GameObject();
|
|
target.AddComponent<Agent>();
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
Destroy(target);
|
|
}
|
|
|
|
public override Steering GetSteering()
|
|
{
|
|
var direction = TargetAux.transform.position - transform.position;
|
|
|
|
if (direction.magnitude <= 0) return base.GetSteering();
|
|
|
|
var targetOrientation = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
|
|
target.GetComponent<Agent>().orientation = targetOrientation;
|
|
|
|
return base.GetSteering();
|
|
}
|
|
}
|
|
} |