31 lines
880 B
C#
31 lines
880 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class ShellBoom : MonoBehaviour
|
|
{
|
|
public UnityEvent onShellAttack = new UnityEvent();
|
|
public bool isPlayer = false;
|
|
public GameObject attackTarget;
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (isPlayer && other.tag == "AttackTarget")
|
|
{
|
|
onShellAttack?.Invoke();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (attackTarget != null)
|
|
{
|
|
Vector3 direction = transform.localPosition - attackTarget.transform.localPosition;
|
|
float step = 1 * Time.deltaTime;
|
|
transform.rotation = Quaternion.LookRotation(direction);
|
|
transform.localPosition = Vector3.MoveTowards(transform.localPosition, attackTarget.transform.localPosition, step);
|
|
}
|
|
}
|
|
|
|
}
|