吃盒子游戏
2014-12-27 19:45
141 查看
今天来学习一下吃盒子游戏
界面设计
首先需要在unity中创建出如下图所示的wall和food还有一个球Sphere
给food中的cube添加标签为Cube1给sphere添加Player
完成之后如图
下面是sphere上挂载的脚本
public Transform enemy;
public Transform enemyRocket;
public Transform player;
float speed = 0.5f;
float i = 0f;
int height = 10;
public float l = 20f;
void Update()
{
transform.Translate(0, 0, -speed * Time.deltaTime);
i -= Time.deltaTime;
if (i <= 0)
{
i = 1;
if (player != null)
{
Vector3 pos = enemy.position - player.position;
GameObject o = GameObject.Instantiate(enemyRocket, enemy.position, Quaternion.LookRotation(pos)) as GameObject;
Destroy(o,0.1f);
}
}
}
void OnTriggerEnter(Collider col)
{
if (col.tag == "rocket")
{
l--;
if (l <= 0)
{
Destroy(this.gameObject);
}
}
if (col.tag == "Player")
{
l--;
if (l <= 0)
{
Destroy(this.gameObject);
}
}
}
下面是cube上挂载的脚本(为关键代码)
void Update () {
transform.Rotate(new Vector3 (10,0,0));
}
void OnTriggerEnter(Collider col)
{
Destroy(this .gameObject );
}
界面设计
首先需要在unity中创建出如下图所示的wall和food还有一个球Sphere
给food中的cube添加标签为Cube1给sphere添加Player
完成之后如图
下面是sphere上挂载的脚本
public Transform enemy;
public Transform enemyRocket;
public Transform player;
float speed = 0.5f;
float i = 0f;
int height = 10;
public float l = 20f;
void Update()
{
transform.Translate(0, 0, -speed * Time.deltaTime);
i -= Time.deltaTime;
if (i <= 0)
{
i = 1;
if (player != null)
{
Vector3 pos = enemy.position - player.position;
GameObject o = GameObject.Instantiate(enemyRocket, enemy.position, Quaternion.LookRotation(pos)) as GameObject;
Destroy(o,0.1f);
}
}
}
void OnTriggerEnter(Collider col)
{
if (col.tag == "rocket")
{
l--;
if (l <= 0)
{
Destroy(this.gameObject);
}
}
if (col.tag == "Player")
{
l--;
if (l <= 0)
{
Destroy(this.gameObject);
}
}
}
下面是cube上挂载的脚本(为关键代码)
void Update () {
transform.Rotate(new Vector3 (10,0,0));
}
void OnTriggerEnter(Collider col)
{
Destroy(this .gameObject );
}
相关文章推荐
- 盒子游戏(The Seventh Hunan Collegiate Programming Contest)
- E - 盒子游戏
- 盒子游戏解题报告
- 盒子游戏(湖南省第七届大学生计算机程序设计竞赛)
- 盒子游戏
- 盒子游戏
- E - 盒子游戏
- 游戏盒子接球
- 畅游无限游戏盒子(五)--adruino远程控灯
- NY562 & CSU1104 盒子游戏【博弈】
- PS4/XBOX迎来全新劲敌!游戏盒子市场前瞻
- CSU 1104 盒子游戏(博弈)
- 畅游无限游戏盒子(二)--推箱子
- 畅游无限游戏盒子(三)--贪吃蛇
- 盒子游戏(The Seventh Hunan Collegiate Programming Contest)
- CSU 1104: 盒子游戏
- VUE+WebPack游戏设计:实现盒子动画和键盘特效
- 软件工程游戏盒子项目需求分析
- 盒子游戏(博弈)
- 取球游戏 今盒子里有n个小球,A、B两人轮流从盒中取球,每个人都可以看到另一个人取了多少个, 也可以看到盒中还剩下多少个,并且两人都很聪明,不会做出错误的判断。