S1402_FXLogic.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Common.Combat.FxAILogic;
  5. using UnityEngine;
  6. public class S1402_FXLogic : MonoBehaviour
  7. {
  8. public Vector3 offRotation;
  9. public Transform[] bodys;
  10. public float[] bodyDis;
  11. private Vector3[] defaultPos;
  12. Quaternion offRotationQ;
  13. private void Awake()
  14. {
  15. bodyDis = new float[bodys.Length];
  16. defaultPos = new Vector3[bodys.Length];
  17. defaultPos[0]=bodys[0].position;
  18. for (int i = 1; i < bodys.Length; i++)
  19. {
  20. Transform t1 = bodys[i - 1];
  21. Transform t2 = bodys[i];
  22. defaultPos[i]=t2.localPosition;
  23. bodyDis[i] = Vector3.Distance(t1.position, t2.position);
  24. }
  25. offRotationQ=Quaternion.Euler(offRotation);
  26. }
  27. private void OnEnable()
  28. {
  29. for (int i = 0; i < bodys.Length; i++)
  30. {
  31. bodys[i].localPosition = defaultPos[i];
  32. }
  33. }
  34. private void LateUpdate()
  35. {
  36. bodys[0].rotation *= Quaternion.Euler(0, 270, 0);
  37. for (int i = 1; i < bodys.Length; i++)
  38. {
  39. Transform t1 = bodys[i - 1];
  40. Transform t2 = bodys[i];
  41. float d = bodyDis[i];
  42. Vector3 dir = (t2.position - t1.position).normalized;
  43. Quaternion q = Quaternion.LookRotation(dir)*offRotationQ;
  44. t2.rotation=q;
  45. t2.position = t1.position + dir * d;
  46. }
  47. }
  48. }