You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Source/Scripts/SquadMember.cs

162 lines
4.3 KiB
C#

3 months ago
using Animancer;
using D2D;
using D2D.Gameplay;
using DG.Tweening;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.AI;
using static D2D.Utilities.CommonGameplayFacade;
[RequireComponent(typeof(Health))]
public class SquadMember : Unit
{
public NavMeshAgent navMesh;
public SexyOverlap overLapObstacle;
public SexyOverlap overLapEnemy;
public MemberClass memberClass;
public Animations animations;
public Health health;
public AnimancerComponent animancer;
public Transform shootPoint;
public int EvolveLevel;
public SquadMember NextEvolution;
[Header("Movement Settings")]
public Vector3 targetVector;
public float rotationLerp = 10f;
public AnimationClip runForward;
[HideInInspector]
public EnemyComponent currentTarget;
public SquadMember evolveTarget;
[SerializeField] internal Color memberColor;
[SerializeField] internal Color bulletColor;
3 months ago
private CharacterCanvas canvas;
private Camera currentCamera;
private Tween punchTween;
internal float reloadTime = 0;
internal float delayBeforeEvolve = 0;
internal float lastShotSoundTime = 0;
public bool IsEvolving;
[Button("Debug Kill")]
private void DebugKill()
{
health.ApplyDamage(null, health.CurrentPoints);
}
private void Awake()
{
navMesh = GetComponent<NavMeshAgent>();
overLapObstacle = GetComponent<SexyOverlap>();
health = GetComponent<Health>();
if (canvas == null)
{
canvas = GetComponentInChildren<CharacterCanvas>();
}
targetVector = transform.forward * 10f + transform.up;
canvas.HealthBar.SetHealth(health);
1 month ago
joystick=GameObject.FindFirstObjectByType<Joystick>();
3 months ago
}
1 month ago
public Vector3 targetRotation;
public Vector3 targetRotationNormalized;
public Joystick joystick;
public float angle;
3 months ago
private void Update()
{
if (IsEvolving)
{
if (evolveTarget == null)
{
StopEvolving();
return;
}
delayBeforeEvolve += Time.deltaTime;
if (delayBeforeEvolve < _gameData.evolveDelay)
{
animancer.Play(animations.Idle);
return;
}
var targetDistance = Vector3.Distance(evolveTarget.transform.position, transform.position);
animancer.Play(runForward);
navMesh.Move((evolveTarget.transform.position - transform.position) * Time.deltaTime * navMesh.speed * (1.7f / targetDistance));
if (targetDistance < 0.5f)
{
_squad.EvolveMembers(this, evolveTarget);
IsEvolving = false;
}
return;
}
1 month ago
targetRotation = targetVector - transform.position;
targetRotationNormalized = targetRotation.normalized;
angle = Vector3.Angle(targetRotationNormalized, joystick.input);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(targetRotation), Time.deltaTime * rotationLerp);
3 months ago
}
public virtual void Init()
{
runForward = animations.RunForward;
if (canvas == null)
{
canvas = GetComponentInChildren<CharacterCanvas>();
}
animancer.Play(animations.Idle);
canvas.EvolutionText.text = $"{Mathf.Pow(2, EvolveLevel + 1)}";
}
public virtual void Shoot(Transform target)
{
}
public virtual void PunchScaleWithDelay(float delay)
{
punchTween.KillTo0();
punchTween = transform.DOPunchScale(Vector3.one * _gameData.punchScale, _gameData.punchDuration, 0, 0).SetDelay(delay);
}
1 month ago
public virtual void SetIdleAnimation()
3 months ago
{
animancer.Layers[0].Play(animations.Idle);
}
public void SetDanceAnimation(AnimationClip animation)
{
animancer.Play(animation, 0.5f);
}
public void Evolve(SquadMember evolveTarget)
{
if (NextEvolution == null)
{
return;
}
animancer.Play(animations.RunForward);
navMesh.ResetPath();
IsEvolving = true;
transform.LookAt(evolveTarget.transform.position);
this.evolveTarget = evolveTarget;
}
private void StopEvolving()
{
animancer.Play(animations.Idle);
IsEvolving = false;
}
}