usa-se a funcao OnDrawGizmos().view sourceprint?Codigo:01.//Draw the gizmo02.public void OnDrawGizmos()03.{04. pos1_aux = (GameObject)pos1.GetChild(0).gameObject;05. pos2_aux = (GameObject)pos2.GetChild(0).gameObject;06. 07. for (float t = 0.0f; t < 1.0f; t += 0.1f) //change this 0.1f to see morepoints in the screen08. {09. Gizmos.DrawIcon(this.GetPointAtTime(t), "BezierCurve.png");10. }11.}Reparem nessa linha de codigo:view sourceprint?1.Gizmos.DrawIcon(this.GetPointAtTime(t),"BezierCurve.png");Esse BezierCurve.png nao e nada mais nada menos do que uma imagem que eucriei 10x10pixels de cor amarela para poder visualizar os pontos no editor. Sevoce nao fizer isso, vai aparecer um quadrado branco. (ps: deve-se colocar aimagem dentro de uma pasta chamada Gizmos).Com a curva criada, basta agora fazer com que um objeto siga a trajetoria. Paraisso, criamos uma interface que chamara a funcao GetPointAtTime(float t) eadicionaremos essa interface a classe BezierCurveview sourceprint?Codigo:01.public interface IBezier02.{03. Vector3 GetPointAtTime(float t);04.}05. 06.public class BezierCurve : MonoBehaviour, IBezier07.{08....09.}Crie um objeto qualquer que seja visivel e adicione um script nele que iramove-lo de acordo com os pontos da trajetoria.view sourceprint?Codigo:01.public class FollowPath : MonoBehaviour02.{03. IBezier Ipath;04. //the path of the object05. public GameObject path;06. 07. //the speed of the object08. public float speed;09. 10. void Start()11. {12. //find the path13. Ipath = path.GetComponent(typeof(IBezier)) as IBezier;14. }15. 16. void Update()17. {18. //make the object follow the path19. transform.position = Ipath.GetPointAtTime(Time.time * speed);20. }21.}Os dois scripts finais ficam assim:BezierCurve.csview sourceprint?Codigo:01.using UnityEngine;02.using System.Collections;03.using System.Collections.Generic;04.using System;05. 06.public interface IBezier07.{08. Vector3 GetPointAtTime(float t);09.}10. 11.public class BezierCurve : MonoBehaviour, IBezier12.{13. //points that will create the bezier curve14. public Transform pos1;15. public Transform pos2;16. private GameObject pos1_aux;17. private GameObject pos2_aux;18. 19. void Awake()20. {21. //pos1_aux and pos2_aux are the children of the main position22. pos1_aux = (GameObject)pos1.GetChild(0).gameObject;23. pos2_aux = (GameObject)pos2.GetChild(0).gameObject;24. }25. 26. //take the point and send to DoBezier4Points to calculate27. public Vector3 GetPointAtTime(float t)28. {29. //create a loop30. t = t % 1.0f;31. if (t < 0)32. {33. t = 1.0f + t;34. }35. 36. Vector3 p0 = pos1.position;37. Vector3 p1 = pos1_aux.transform.position;38. Vector3 p2 = pos2_aux.transform.position;39. Vector3 p3 = pos2.position;40. 41. return DoBezier4Points(t, p0, p1, p2, p3);42. }43. 44. //calculate the position of the point at time t45. public Vector3 DoBezier4Points(float t, Vector3 p0, Vector3 p1, Vector3 p2,Vector3 p3)46. {47. Vector3 point = Vector3.zero;48. float OneMinusT = (1f - t);49. 50. point += (Mathf.Pow(OneMinusT, 3) * p0);51. point += (3 * Mathf.Pow(OneMinusT, 2) * t * p1);52. point += (3 * OneMinusT * Mathf.Pow(t, 2) * p2);53. point += (Mathf.Pow(t, 3) * p3);54. 55. return point;56. }57. 58. //Draw the gizmo59. public void OnDrawGizmos()60. {61. //this is necessary to work in the editor mode62. pos1_aux = (GameObject)pos1.GetChild(0).gameObject;63. pos2_aux = (GameObject)pos2.GetChild(0).gameObject;64. 65. //Show the path in the screen. Changing the 0.1f will increase/decrease thepoints in the screen66. for (float t = 0.0f; t < 1.0f; t += 0.1f)67. {68. Gizmos.DrawIcon(this.GetPointAtTime(t), "BezierCurve.png");69. }70. }71.}FollowPath.csview sourceprint?Codigo:01.using UnityEngine;02.using System.Collections;03. 04.public class FollowPath : MonoBehaviour05.{06. IBezier Ipath;07. //the path of the object08. public GameObject path;09. 10. //the speed of the object11. public float speed;12. 13. void Start()14. {15. //find the path16. Ipath = path.GetComponent(typeof(IBezier)) as IBezier;17. }18. 19. void Update()20. {21. //make the object follow the path22. transform.position = Ipath.GetPointAtTime(Time.time * speed);23. }24.}Resultado da primeira parte SEGUNDA PARTETrajetoria com linha bezier entre