2d progress
This commit is contained in:
1 parent
9f026b76d6
commit
63c3549673
70 files changed
+1008
-6260
No files matched your search
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using DG.Tweening.Core;
|
||||
using DG.Tweening.Plugins.Options;
|
||||
using PrimeTween;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Platformer.Entity.Enemies
|
||||
@@ -10,50 +7,56 @@ namespace Code.Example.Platformer.Entity.Enemies
|
||||
public class Bee : Entity
|
||||
{
|
||||
[SerializeField] private List<Transform> partolPoints;
|
||||
private bool _onPatrol;
|
||||
private bool _onPatrolMoveDamnit;
|
||||
private int _currentPartolPoint;
|
||||
[SerializeField] private bool onPatrol = true;
|
||||
private int _currentPatrolPoint;
|
||||
|
||||
private Transform _currentTarget;
|
||||
private TweenerCore<Vector3, Vector3, VectorOptions> _patrolAction;
|
||||
private Vector3 _velocity = new Vector3(1,1,1);
|
||||
[SerializeField] private Transform _currentTarget;
|
||||
|
||||
private Tween _patrolAction;
|
||||
|
||||
protected override void Move()
|
||||
{
|
||||
if (_onPatrol && !_onPatrolMoveDamnit)
|
||||
{
|
||||
_onPatrolMoveDamnit = true;
|
||||
_patrolAction = transform.DOMove(partolPoints[_currentPartolPoint].position, 3f);
|
||||
_patrolAction.onComplete += OnControlPointReached;
|
||||
if (onPatrol && !_patrolAction.isAlive)
|
||||
{
|
||||
_patrolAction = Tween
|
||||
.PositionAtSpeed(transform,partolPoints[_currentPatrolPoint].position, 0.5f)
|
||||
.OnComplete(target: this, target => target.OnControlPointReached());
|
||||
}
|
||||
else
|
||||
else if(_currentTarget)
|
||||
{
|
||||
|
||||
var direction = _currentTarget.position - transform.position;
|
||||
direction.Normalize();
|
||||
var targetPosition = _currentTarget.position + direction * -2f;
|
||||
|
||||
UnityEngine.Debug.DrawLine(transform.position, targetPosition, Color.red);
|
||||
|
||||
transform.DOMove(_currentTarget.position, 2f).onComplete += OnControlPointReached;
|
||||
|
||||
transform.position = Vector3.SmoothDamp(transform.position,_currentTarget.position,ref _velocity, 1f);
|
||||
// Tween
|
||||
// .PositionAtSpeed(transform, _currentTarget.position, 1f).OnUpdate(transform, );
|
||||
// // .OnComplete(OnControlPointReached);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnControlPointReached()
|
||||
{
|
||||
if (++_currentPartolPoint >= partolPoints.Count) _currentPartolPoint = 0;
|
||||
_onPatrolMoveDamnit = false;
|
||||
{
|
||||
if (++_currentPatrolPoint >= partolPoints.Count) _currentPatrolPoint = 0;
|
||||
}
|
||||
|
||||
public void GotTarget(Transform other)
|
||||
{
|
||||
_onPatrol = false;
|
||||
onPatrol = false;
|
||||
|
||||
_currentTarget = other;
|
||||
_patrolAction?.Complete();
|
||||
|
||||
_patrolAction.Stop();
|
||||
}
|
||||
|
||||
public void LostTarget()
|
||||
{
|
||||
_onPatrol = true;
|
||||
_currentTarget = null;
|
||||
onPatrol = true;
|
||||
_currentTarget = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user