| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- /**瞄准器负载检测 */
- public class AimLoadChecker : MonoBehaviour
- {
- [SerializeField] GameObject outTip;
- void Update()
- {
- bool needActiveOutTip = false;
- if (ArmBow.ins && ArmBow.ins.IsCanShoot() && TargetBody.ins) {
- RaycastHit ray = CrossHair.ins.GetRaycastHit();
- if (ray.transform && ray.transform.gameObject.name == "TargetBody") {
- float mySpeed = Arrow.speed;
- if (GameAssistUI.ins) {
- mySpeed *= GameAssistUI.ins.shootScaleValue;
- }
- Vector3 destination = ray.point;
- Vector3 startPoint = BowCamera.ins.transform.position;
- float deltaX = Mathf.Sqrt(
- Mathf.Pow(destination.x - startPoint.x, 2) +
- Mathf.Pow(destination.z - startPoint.z,2)
- );
- float deltaY = destination.y - startPoint.y;
- float a = 0.5f * Physics.gravity.y * Mathf.Pow(deltaX, 2) / Mathf.Pow(mySpeed, 2);
- float b = deltaX;
- float c = a - deltaY;
- bool hasParabolaAngle = Mathf.Pow(b, 2) - 4 * a * c >= 0;
- if (hasParabolaAngle) {
- float res1 = (-b + Mathf.Pow(Mathf.Pow(b, 2) - 4*a*c, 0.5f)) / (2 * a);
- float res2 = (-b - Mathf.Pow(Mathf.Pow(b, 2) - 4*a*c, 0.5f)) / (2 * a);
- float parabolaAngle = Mathf.Min(Mathf.Atan(res1), Mathf.Atan(res2)) / Mathf.PI * 180;
- needActiveOutTip = parabolaAngle > 5;
- }
- }
- }
- ActiveOutTip(needActiveOutTip);
- }
- public void ActiveOutTip(bool value)
- {
- if (outTip.activeSelf != value) {
- outTip.SetActive(value);
- }
- }
- }
|