Unity3d入门代码–摄像机跟随
摄像机跟随的代码
代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class camerafollow : MonoBehaviour {
public Transform target;
public float speed =
5f;
Vector3 offset;
void Awake()
{
offset = transform.position - target.position;
}
void FixedUpdate()
{
Vector3 targetcampos = target.position + offset;
transform.position = Vector3.Lerp(transform.position,targetcampos,speed*Time.deltaTime);
}
}
最后不要忘记在unity编辑器中给target赋值
转载请注明原文地址: https://ju.6miu.com/read-671383.html