秉着学习碰撞体的态度进行学习,对掘地求生进行仿制。
新建2D项目
首先是导入场景构建。附带碰撞体


创建主角和视角,控制相机移动确保平滑过度

以下是参考代码
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target;
void Start()
{
GetComponent<Camera>().transparencySortMode = TransparencySortMode.Orthographic;
}
void FixedUpdate()
{
Vector3 moveVec = target.position - GetComponent<Camera>().transform.position;
moveVec.z = 0;
GetComponent<Camera>().transform.position += moveVec * Time.fixedDeltaTime * 4.0f;
}
}
using UnityEngine;
public class Hand : MonoBehaviour
{

本文分享了使用Unity进行2D游戏开发的心得,特别是针对《掘地求生》的仿制过程,包括新建2D项目,设置场景碰撞体,创建主角与相机平滑跟随的实现。文中提供了关键代码片段,如CameraFollow、Hand、Head和PlayerControl类,最后还提及了资源包的使用。
最低0.47元/天 解锁文章
2320

被折叠的 条评论
为什么被折叠?



