mycj_demo/mycj/Assets/Game/Scripts/Application/Object/FBBallBullet.cs
2024-12-02 09:37:47 +08:00

101 lines
2.8 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Felix-BangFBBallBullet
//   へ     /|
//  /7    ∠_/
//  / │    
//  Z _,    /`ヽ
// │     ヽ   /  〉
//  Y     `  /  /
// イ● 、 ●  ⊂⊃〈  /
// ()  へ    | \〈
//  >ー 、_  ィ  │
//  / へ   / ノ<|
//  ヽ_ノ  (_  │//
//  7       |
//  ―r ̄ ̄`ー―_
// Describe球形子弹
// Createtime2018/10/18
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace FBApplication
{
public class FBBallBullet : FBBullet
{
#region
//目标
public FBMonster Target { get; private set; }
//移动方向
public Vector3 Direction { get; private set; }
#endregion
#region Unity回调
protected override void Update()
{
//已爆炸无需跟踪
if (f_isExploded)
return;
//目标检测
if (Target != null)
{
if (!Target.IsDead)
{
//计算方向
Direction = (Target.transform.position - transform.position).normalized;
}
//角度
LookAt();
//移动
transform.Translate(Direction * Speed * Time.deltaTime, Space.World);
//打中目标
if (Vector3.Distance(transform.position, Target.transform.position) <= FBConsts.DotClosedDistance)
{
//敌人受伤
Target.Damage(Attack);
//爆炸
Explode();
}
}
else
{
//移动
transform.Translate(Direction * Speed * Time.deltaTime, Space.World);
//边界检测
if (!f_isExploded&& !MapRect.Contains(transform.position))
Explode();
}
}
#endregion
#region
public void Load(int bulletID, int level, Rect mapRect, FBMonster monster)
{
Load(bulletID, level, mapRect);
Target = monster;
//计算方向
Direction = (Target.transform.position - transform.position).normalized;
}
#endregion
#region
void LookAt()
{
float angle = Mathf.Atan2(Direction.y, Direction.x);
Vector3 eulerAngles = transform.eulerAngles;
eulerAngles.z = angle * Mathf.Rad2Deg - 90;
transform.eulerAngles = eulerAngles;
}
#endregion
}
}