Unity跑酷类游戏自动生成销毁地图
来源:互联网 发布:你是我的兄弟网络电影 编辑:程序博客网 时间:2024/04/29 20:47
using UnityEngine;
using System.Collections;
public class move : MonoBehaviour {
Vector3 dir;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
dir = RoadManager .Instance .GetDir (transform .position );
transform .Translate (dir*Time .deltaTime );
}
}
using UnityEngine;
using System.Collections;
public class Road : MonoBehaviour {
public Transform [] wayPoints;//路的标示
public Vector3 endPosition;//最后位置
void OnEnable(){
endPosition = wayPoints [wayPoints .Length - 1].position ;
}
void Awake(){
}
}
using UnityEngine;
using System.Collections;
public class RoadManager : MonoBehaviour {
public static RoadManager Instance;
void Awake(){
Instance = this ;
}
private Road previousRoad;//上一个道路
public Road currentRoad;//当前道路
public Road nextRoad;//下一个道路
public GameObject roadPrefab;//道路预设体
//生成道路
public void CreateRoad(){
GameObject newRoad = (GameObject ) Instantiate (roadPrefab ,nextRoad.endPosition,Quaternion .identity );
//随即一个颜色
float r = Random .Range (0f, 1f);
float g = Random .Range (0f, 1f);
float d= Random .Range (0f, 1f);
Color color = new Color (r,g,d);
newRoad .GetComponentInChildren <MeshRenderer >().material .color = color ;
previousRoad = currentRoad ;
currentRoad = nextRoad;
nextRoad = newRoad .GetComponent <Road>();
//Destroy (previousRoad.gameObject ,1f);
}
Vector3 dir;//代表方向
int targetIndex = 1;
public Vector3 GetDir(Vector3 pos){//参数代表玩家位置
dir = currentRoad .wayPoints [targetIndex].position - currentRoad .wayPoints [targetIndex -1].position ;
//如果玩家移动到下一个点
if (Vector3 .Distance (pos ,currentRoad .wayPoints [targetIndex ].position )< 1f) {
targetIndex ++;
}
//到达了最后一个点
if (targetIndex == currentRoad .wayPoints .Length ) {
targetIndex = 1;
CreateRoad ();
}
return dir ;
}
}
- Unity跑酷类游戏自动生成销毁地图
- Unity游戏小地图生成
- [原创] CGDC2009讲稿 - 游戏地图自动生成
- 程序自动生成地图
- 自动生成地图 物体 Generator
- Unity 控制游戏对象,显示小地图
- Unity中使用柏林噪声生成地图
- unity 游戏物体自动循环移动脚本
- 自动生成Google sitemaps地图文件
- Data Modle:自动生成战争地图
- dede自动生成RSS和网站地图
- VBA案例5:自动生成地图
- Unity修改自动生成的代码模板
- Unity之UGUI脚本自动生成
- 【Unity】游戏体销毁重新实例化GameObject后相同结构动画的衔接
- Unity实战 RTS3D即时战略游戏开发(十三) 伤害更新信息显示、销毁单位、爆炸效果
- unity 游戏报错时,让游戏自动暂停
- Unity游戏开发--30s制作精美地图
- 最大连续和---变种版
- Linux下执行一些命令前加sudo时出现command not found的原因
- 关于使用eclipse编写程序
- MVC4学习笔记01
- 常用排序算法
- Unity跑酷类游戏自动生成销毁地图
- 硬件以及编程的一些底层概念
- 侃侃自己的IT面试经历
- 高阶函数
- Codeforces Round #324 (Div. 2)C. Marina and Vasya
- The King’s Problem(tarjan求强连通分量缩点+匈牙利求有向无环图的最小路径覆盖)
- JAVA常见面试题整理
- 类图关系在代码中的体现
- 常见的几个Qt编程问题的处理