当前位置:网站首页>Unity学习笔记–无限地图
Unity学习笔记–无限地图
2022-07-26 14:11:00 【renwen1579】
Unity学习笔记–无限地图
在很多简单的单机跑酷或者赛车游戏中,不需要建立一个很大的地图,可以使用小地图拼接的方式实现无限地图的功能。
具体思想是:玩家处于地图中的某个位置,当快要走出边界时,地图在人物的前方再次生成一个进行拼接,看起来地图是永远跑不完的样子。
unity里面用两个Plane与一个cube做介绍:

默认的Plane的尺寸为10x10m,两个Plane要在一个目标下;
用Cube代替玩家,沿Z方向拖动cube时,plane会跟随交替生成;
话不多说,上代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class AddPlane : MonoBehaviour
{const float width = 10f;//这里是平面的宽度
public Transform player;
Vector3 initPos;
void Start()
{
initPos = transform.position;
}void Update()
{
float totalWidth = width*2f;// * backGroundNum;
float distZ = player.position.z - initPos.z;//实时计算玩家与插入点的距理
int n = Mathf.RoundToInt(distZ / totalWidth);//四舍五入一下var pos = initPos;
pos.z += n * totalWidth;
transform.position = pos;
}
}
边栏推荐
- Job 7.25 sorting and searching
- Explain four interesting NPM usages with charts
- 12437 words, take you to explore the principle of RPC communication
- C language_ Combination of structure and array
- Basic knowledge about memory chips
- C语言_结构体和数组的结合
- Instructions for various interfaces of hand-held vibrating wire collector vh03
- IDEA(warning)No artifacts configured
- 『云原生』KubeSphere可插拔组件之DevOps系统
- UE4 智能指针和弱指针
猜你喜欢

android安全基础知识学习

Latest battle report: Ten certifications and five best practices

PHP uses sqlserver

"Intermediate and advanced test questions": what is the implementation principle of mvcc?

【论文阅读】GRAW+:A Two-View Graph Propagation Method With Word Coupling for Readability Assessment

大脑带来的启发:深度神经网络优化中突触整合原理介绍

Learning basic knowledge of Android security

多态案例-制作饮品

融合多自然语言处理任务的中医辅助诊疗方案研究——以糖尿病为例
![[ostep] 02 virtualized CPU - process](/img/0b/3f151ccf002eb6c0469bf74072a3c5.png)
[ostep] 02 virtualized CPU - process
随机推荐
Understand the meaning of length in MySQL data types
『SignalR』.NET使用 SignalR 进行实时通信初体验
Leetcode question type priority queue (TOPK question)
URL的使用下载资源
C language Snake linked list and pointer practice
Devops system of "cloud native" kubesphere pluggable components
Jzoffer51- reverse pairs in the array (merge sort solution)
How to quickly design a set of cross end components that support rendering rich text content
二叉树的层序遍历(C语言实现)
Mlx90640 infrared thermal imager temperature sensor module development notes (6)
基于机器学习的技术术语识别研究综述
敏捷开发与DevOps的对比
How can red star Macalline design cloud upgrade the traditional home furnishing industry in ten minutes to produce film and television level interior design effects
Ten thousand words long article, talking about the blueprint of enterprise digital modeling
Circular queue (implemented in C language)
Add a display horizontal line between idea methods
Research on prediction of user churn in online health community based on user portrait
Large and small end mode
Solve the problem that JUnit of idea console cannot be input with scanner
2022-07-26 Daily: the first anniversary of the establishment of alphafold DB database, research on the lighting point of official promotion