50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Cysharp.Threading.Tasks;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
public class BattleBlobArcher: BattleBlobJob
|
|
{
|
|
public GameObject ArrowPrefab;
|
|
|
|
private void Awake()
|
|
{
|
|
GetComponent<BattleBlob>().AttackDistance = 60f;
|
|
ArrowPrefab = Resources.Load<GameObject>("Arrow");
|
|
var animator = GetComponent<Animator>();
|
|
animator.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("ArchAnimator");
|
|
}
|
|
|
|
public async override UniTaskVoid Attack(BattleBlob battleBlob, GameObject target)
|
|
{
|
|
// print("attack!");
|
|
var go = Instantiate(ArrowPrefab);
|
|
go.transform.position = battleBlob.transform.position;
|
|
var arrow = go.GetComponent<ArrowBehaviour>();
|
|
if (arrow)
|
|
{
|
|
// Vector3 targetPosition = target.gameObject.transform.position -
|
|
// (Vector3.left *
|
|
// (arrow.transform.position - target.gameObject.transform.position)
|
|
// .sqrMagnitude / arrow.speed) ;
|
|
var targetPosition = target.gameObject.transform.position;
|
|
arrow.target = targetPosition;
|
|
}
|
|
|
|
var trigger = go.GetComponent<TriggerDetection>();
|
|
if (trigger)
|
|
{
|
|
trigger.onTriggerEnter += collider =>
|
|
{
|
|
var enemy = collider.GetComponent<EnemyController>();
|
|
if (!enemy) return;
|
|
if (enemy.isDead) return;
|
|
enemy.Health -= (int)battleBlob.AttackDamage;
|
|
Destroy(go.gameObject);
|
|
};
|
|
}
|
|
}
|
|
}
|