float a = 0;//声明一个浮点数存放a,用于表示弧度
public void Update()
{
a +=0.01f;//弧度每帧增加0.01f
this.transform.Translate(this.transform.forward * 10*Time.deltaTime);//物体朝着自己的z轴正方向移动,移动速度为10*deltatime
this.transform.Translate(this.transform.up *Mathf.Sin(a)*0.1f);//物体y轴方向移动是sin曲线形式(mathf.sin(a)表示将a这个弧度传入并转化为对应数值)(后面*0.1f是为了减弱速度)
}
用法:
1.在unity中创建一个任意模型,将此脚本挂载这个模型上即可实现sin曲线移动
2.con/tan曲线移动也简单,只需要将最后一句中的mathf.sin(a)换成mathf.cos(a)/mathf.tan(a)即可