Fish.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using UnityEngine;
  3. public class Fish : MonoBehaviour
  4. {
  5. public void Init(Vector3[] paths, float minTime, float maxTime, float lookTime)
  6. {
  7. this.itweenPath = paths;
  8. this.minTime = minTime;
  9. this.maxTime = maxTime;
  10. this.lookTime = lookTime;
  11. }
  12. public void MovePath()
  13. {
  14. if (!this.isInit)
  15. {
  16. this.go = new GameObject("LookTarget");
  17. this.go.transform.parent = base.gameObject.transform.parent;
  18. this.go.layer = base.gameObject.layer;
  19. this.go.transform.position = this.itweenPath[1];
  20. this.isInit = true;
  21. }
  22. this.pathNo++;
  23. if (this.pathNo > this.itweenPath.Length - 1)
  24. {
  25. this.pathNo = 1;
  26. }
  27. int num = (this.pathNo + 1 <= this.itweenPath.Length - 1) ? (this.pathNo + 1) : 1;
  28. iTween.MoveTo(this.go, iTween.Hash(new object[]
  29. {
  30. "position",
  31. this.itweenPath[num],
  32. "time",
  33. UnityEngine.Random.Range(this.minTime, this.maxTime),
  34. "easeType",
  35. "linear",
  36. "isLocal",
  37. true
  38. }));
  39. iTween.MoveTo(base.gameObject, iTween.Hash(new object[]
  40. {
  41. "position",
  42. this.itweenPath[this.pathNo],
  43. "time",
  44. UnityEngine.Random.Range(this.minTime, this.maxTime),
  45. "easeType",
  46. "linear",
  47. "oncomplete",
  48. "MovePath",
  49. "isLocal",
  50. true
  51. }));
  52. }
  53. private void Update()
  54. {
  55. base.transform.LookAt(this.go.transform);
  56. }
  57. private int pathNo;
  58. private Vector3[] itweenPath;
  59. private float minTime;
  60. private float maxTime;
  61. private float lookTime;
  62. private bool isInit;
  63. private GameObject go;
  64. }