| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using UnityEngine;
- /* 组件-射击目标-靶子 */
- public class TargetBodyNew : MonoBehaviour
- {
- float distance = 10f;
- public int playerIndex;
- public static TargetBodyNew ins;
- void Start()
- {
- ins = this;
- SetDistance(distance);
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- }
- public void Hit(ArrowNew2 arrow, Vector3 hitPosition, int attackerPlayerIndex)
- {
- transform.Find("PointSignLastHit")?.GetComponent<PointSignLastHitNew>()?.Show(hitPosition);
- arrow.Hit();
- AudioMgr.ins.PlayHit(AudioMgr.GetAudioSource(gameObject));
- bool hitTarget = false;
- float maxSize = Vector3.Distance(transform.Find("CenterPoint").position, transform.Find("SidePoint").position);
- float radius = measureRadius(hitPosition);
- float score = Mathf.Clamp(10f - radius / maxSize * 10f, 0, 9.9f) + 1;
- if (score >= 1)
- {
- score = (float)System.Math.Round(score, CommonConfig.ringsPrecision);
- if (playerIndex != attackerPlayerIndex) score = 0;
- GameController.ins.HitTarget(score, attackerPlayerIndex);
- //AudioMgr.ins.PlayCheer(true);
- hitTarget = true;
- }
- if (!hitTarget) GameController.ins.HitTarget(0);
- arrow.hitType = hitTarget ? ArrowNew2.HitType.TargetInRing : ArrowNew2.HitType.TargetOutRing;
- }
- float measureRadius(Vector3 position)
- {
- return Vector3.Distance(transform.Find("CenterPoint").position, position);
- }
- public void SetDistance(float value)
- {
- distance = value;
- Vector3 v3 = transform.parent.localPosition;
- v3.z = GameMgr.RealSizeToGameSize(value);
- transform.parent.localPosition = v3;
- }
- public float GetDistance()
- {
- return distance;
- }
- }
|