TargetObjDeg.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /****************************
  2. summary:
  3. ****************************/
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. public class TargetObjDeg : MonoBehaviour
  8. {
  9. public bool state;
  10. public Transform player;
  11. private float y;
  12. private Vector3 disPos;
  13. private float dic;
  14. private Vector3 dir;
  15. private Vector3 cross;
  16. private float dot;
  17. private float deg;
  18. private void Start()
  19. {
  20. state = false;
  21. }
  22. public void FixedUpdate()
  23. {
  24. if (!state)
  25. return;
  26. dic = Mathf.Abs(Vector3.Distance(player.position, transform.position));
  27. if (dic < 2.5f)
  28. {
  29. dir = player.position - transform.position;
  30. cross = Vector3.Cross(transform.forward, dir);
  31. dot = Vector3.Dot(transform.forward, dir.normalized);
  32. deg = Mathf.Acos(dot) * Mathf.Rad2Deg;
  33. //Debug.Log(" ");
  34. //dic =Mathf.Abs( Vector3.Distance(player.position, transform.position));
  35. Debug.Log("cross.y : " + cross.y + "deg : " + deg);
  36. // VuforiaManager.Instance.text.text = "Dot : " + dot + " deg : " + deg + " dic: " + dic;
  37. if (cross.y < 0 && deg >= 165)
  38. {
  39. VuforiaManager.Instance.isCorrect = true;
  40. }
  41. else if(VuforiaManager.Instance.isCorrect)
  42. {
  43. VuforiaManager.Instance.isCorrect = false;
  44. }
  45. //Vector3 pDir = transform.position - player.position;
  46. //Vector3 pCross = Vector3.Cross(player.forward, pDir);
  47. //float pDot = Vector3.Dot(player.forward, pDir.normalized);
  48. //float pDeg = Mathf.Acos(pDot) * Mathf.Rad2Deg;
  49. }
  50. }
  51. }