123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Bunny : MonoBehaviour
- {
-
-
-
-
- public Vector3 InitialPosition { get; private set; }
-
-
-
- public bool IsMoving { get; private set; }
-
-
-
- private BunnySpawner bunnyspawner;
-
-
-
- private Transform centerpoint;
-
-
-
- private ZEDPlaneDetectionManager planeManager;
-
-
-
- private Rigidbody rb;
-
-
-
- [HideInInspector]
- public Animator anim;
-
- void Start()
- {
- IsMoving = false;
-
- planeManager = FindObjectOfType<ZEDPlaneDetectionManager>();
- rb = GetComponent<Rigidbody>();
- anim = GetComponent<Animator>();
- InitialPosition = transform.position;
-
- if (transform.GetChild(2) != null)
- {
- centerpoint = transform.GetChild(2);
- }
- else
- {
- centerpoint = transform;
- }
- }
-
-
-
-
- public void SetMySpawner(BunnySpawner spawner)
- {
- bunnyspawner = spawner;
- }
-
-
-
- public void GetHit(bool hit)
- {
- GetComponent<Rigidbody>().drag = 0f;
- GetComponent<Rigidbody>().angularDrag = 0.5f;
- StartCoroutine(HitDelay(hit));
- }
-
-
-
-
- IEnumerator HitDelay(bool hit)
- {
-
- yield return new WaitForSeconds(0.1f);
- if (hit)
- {
-
- IsMoving = true;
- }
- else
- {
- rb.isKinematic = true;
- yield return new WaitForSeconds(1f);
- bunnyspawner.SpawnUI(transform.position);
- }
-
- for (int i = 0; i < planeManager.hitPlaneList.Count; i++)
- {
- Destroy(planeManager.hitPlaneList[i].gameObject);
- planeManager.hitPlaneList.RemoveAt(i);
- }
- }
-
-
-
-
- private void FixedUpdate()
- {
-
- if (IsMoving)
- {
-
- Vector3 predictedPos = centerpoint.position + (rb.velocity * (Time.deltaTime * 2.5f));
- transform.rotation = Quaternion.LookRotation(rb.velocity.normalized);
-
- foreach (ZEDManager manager in ZEDManager.GetInstances())
- {
- if (ZEDSupportFunctions.HitTestAtPoint(manager.zedCamera, manager.GetMainCamera(), predictedPos))
- {
-
- if (planeManager.DetectPlaneAtHit(manager, manager.GetMainCamera().WorldToScreenPoint(predictedPos)))
- {
- bunnyspawner.SpawnUI(predictedPos);
- IsMoving = false;
- }
- else
- {
- IsMoving = false;
- bunnyspawner.SpawnUI(predictedPos);
- rb.velocity = Vector3.Reflect(rb.velocity / 2, transform.forward);
- }
- break;
- }
- }
- }
- }
- }
|