需求描述:炸弹爆炸时有一个范围,从炸弹中心(等效为点)到玩家(等效为圆)的边缘,做一条切线,然后计算切点的坐标,来判断玩家是否受到伤害。
代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bomb : MonoBehaviour
{
//将脚本挂载到 Bomb 上,需要将 Player 设为公开变量,然后拖拽进来。
public GameObject player;
//设为公开变量,方便在面板中查看
public float angle;//半径与两点间距离的夹角,也是单位向量旋转的角度
public float b;//两点间距离
public Vector3 vec_01;//两点间方向
public Vector3 vec_02;//切点
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()