You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
54 lines
1.4 KiB
using System;
|
|
using UnityEngine;
|
|
|
|
public class AttatchBullet : BulletBase
|
|
{
|
|
[SerializeField] GameObject bulletRoot;
|
|
[SerializeField] GameObject attatchingEffect;
|
|
|
|
public Transform Target { get; private set; }
|
|
public bool IsAttaching { get; private set; }
|
|
|
|
public Action OnAttatching;
|
|
|
|
protected override bool UpdateBullet(float deltaTime)
|
|
{
|
|
if (Target is null) return false;
|
|
|
|
Vector2 toTarget = Target.position - transform.position;
|
|
|
|
if(!IsAttaching)
|
|
{
|
|
transform.position += (Vector3)toTarget.normalized * Speed * deltaTime;
|
|
HeadDirection = toTarget;
|
|
|
|
if(toTarget.sqrMagnitude <= 1f)
|
|
{
|
|
HeadDirection = Vector2.right;
|
|
IsAttaching = true;
|
|
|
|
bulletRoot.gameObject.SetActive(false);
|
|
attatchingEffect?.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
transform.position = Target.position;
|
|
OnAttatching?.Invoke();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override void Fire(Transform target = null, bool resetLifeTime = true)
|
|
{
|
|
if (target is null) return;
|
|
|
|
base.Fire(target, resetLifeTime);
|
|
|
|
Target = target;
|
|
IsAttaching = false;
|
|
bulletRoot?.gameObject.SetActive(true);
|
|
attatchingEffect?.gameObject.SetActive(false);
|
|
}
|
|
}
|