阅读时长: 10分钟
阅读难度: 初级
阅读收获: 可以在unity自由的完成点对点的移动过程
例子地址: https://gitee.com/asiworld/unity3d-basic-function-code
using System.Collections;
using UnityEngine;
public class movement_1 : MonoBehaviour
{
// Start is called before the first frame update
IEnumerator Start()
{
yield return new WaitForSeconds(1.0f);
transform.position = new Vector3(transform.position.x + 10, transform.position.y, transform.position.z);
}
// Update is called once per frame
void Update()
{
}
}
9月9日1
using UnityEngine;
public class movement_2 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = Vector3.Lerp(transform.position, new Vector3(5, transform.position.y, transform.position.z), Time.deltaTime);
}
}
9月9日2
using DG.Tweening;
using UnityEngine;
public class movement_3 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
transform.DOMove(new Vector3(transform.position.x + 10, transform.position.y, transform.position.z), 2.0f);
}
// Update is called once per frame
void Update()
{
}
}
9月9日3
在project视图中的对应目录下创建animator
在project视图中的对应目录下创建animation
在Hierarchy视图中创建物体
关联animation和animator
关联animator和物体
点击ctrl/command+6打开animation视图
在第n针上创建关键帧内容为对应物体的位置
点击play按键
9月9日4