这一次是我自己编程了一个物体的移动轨迹,我让物体在z轴上呈现直线移动,而在x轴上进行sin函数一样的移动,所以最后会呈现出物体走s形。
如何使用sin函数呢?
首先在最前面申明using System;
然后Math.Sin()进行调用就行了。
Math是一个包含多种数学工具的数学包:Sin,Cos,Sqrt,Pow等。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class SimpleLogic : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
GameObject obj = this.gameObject;
Vector3 pos = obj.transform.localPosition;
pos.z += (float)0.01;
pos.x =(float)Math.Sin(pos.z);
obj.transform.localPosition = pos;
}
}