49
社区成员
发帖
与我相关
我的任务
分享
如何使用 LookAt 函数使一个游戏对象的变换组件面向另一个游戏对象的变换组件。
using UnityEngine;
using System.Collections;
public class CameraLookAt : MonoBehaviour
{
public Transform target;
void Update ()
{
transform.LookAt(target);
}
}
在制作游戏时,有时可以在两个值之间进行线性插值。这是通过 Lerp 函数来完成的。
// 在此示例中,result = 4
float result = Mathf.Lerp (3f, 5f, 0.5f);
Vector3 from = new Vector3 (1f, 2f, 3f);
Vector3 to = new Vector3 (5f, 6f, 7f);
// 此处 result = (4, 5, 6)
Vector3 result = Vector3.Lerp (from, to, 0.75f);
void Update ()
{
light.intensity = Mathf.Lerp(light.intensity, 8f, 0.5f * Time.deltaTime);
}