用射线确定目标点,环绕包围目标点。

public Vector3 GetRandomRadianPoint(Vector3 targetPos)
        {
            float angle = Random.Range(-30, 30);
            Vector3 myPos = Owner.transform.position;
            Vector3 point = Quaternion.AngleAxis(angle, Vector3.up) * ((myPos - targetPos).normalized) * Random.Range(0,3);
            Vector3 resultVec3 = targetPos + point;
            return resultVec3;
        }

这个函数来确定每一个鱼(敌人)跑过来的目标点,就像一群敌人跑过来环形包围一个人那种感觉。

判断鼠标点击,判断点击在UI上。用射线来确定目标点。上面就是移动向目标点选取环形围绕点。

if (Input.GetMouseButtonDown(0))
{
                    
    if (CheckGuiRaycastObjects())
    {
        Debug.LogFormat("-------------------------------->>>  点击在UI上");
        return;
    }

    Vector2 screemMousePos = Input.mousePosition;
    Ray ray = camera.ScreenPointToRay(screemMousePos);                  
    RaycastHit hit;
    if (Physics.Raycast(ray, out hit, 100))
    {
        //if (hit.collider.tag == "FishPond")
        Debug.LogFormat("-------------------------------->>>  {0}", hit.point.ToString());
        EatPoistion = hit.point;
        Debug.DrawRay(camera.transform.position, EatPoistion - camera.transform.position, Color.red, 10);
        FishAI[] fishArr = FishRoot.GetComponentsInChildren<FishAI>();
        for (int i = 0; i < fishArr.Length; i++)
        {
            FishAI ai = fishArr[i];
            ai.ChangeState(new FishMovetoEat());
        }
        Debug.DrawRay(camera.transform.position, EatPoistion - camera.transform.position, Color.red, 10);
    }
}

bool CheckGuiRaycastObjects()
{
    PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
    eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

    List<RaycastResult> results = new List<RaycastResult>();
    EventSystem.current.RaycastAll(eventDataCurrentPosition, results);

    return results.Count > 0;
}    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值