【文件属性】:
文件名称:unity + win8.1 apps 小游戏demo
文件大小:266KB
文件格式:RAR
更新时间:2017-08-13 12:58:59
untiy win8.1 apps demo 小游戏
http://blog.csdn.net/xiaoxiao108/article/details/37882295
unity3d用的人挺多,本来想写个3d游戏试试,额,貌似挺麻烦,先用unity写个简单的2d游戏吧
(adsw回车 或者 触摸屏虚拟摇杆)
开发环境 unity4.5.1f3 vs2013 express win8.1
实现方法如下
1.创建自己的坦克Sprite
2.创建敌方坦克Prefab
3.创建子弹Prefab
4.添加虚拟摇杆
5.碰撞检测
具体实现
1.控制自己坦克的代码
[csharp] view plaincopy
if (Input.GetKey (KeyCode.W)) {
Rotate (0);
}
else if (Input.GetKey (KeyCode.S)) {
Rotate (180);
} else if (Input.GetKey (KeyCode.A)) {
Rotate (90);
} else if (Input.GetKey (KeyCode.D)) {
Rotate (270);
}
i++;
if (i == 10) {i=0;
if (Input.GetKey (KeyCode.Return)||rotateJoystick.tapCount > 0) {
m.tag = "GOOD";
Instantiate (m, transform.position, transform.rotation);
}
}
2.控制地方坦克的代码
[csharp] view plaincopy
if (step == 0)
{
int i=Random.Range(0, 4);
Rotate(angles[i]);
step = Random.Range(0, 20) + 85;
if(Random.Range(0,50)>40)
{
m.tag="BAD";
Instantiate(m, transform.position, transform.rotation);
}
}
else
{
step--;
}
transform.Translate (Vector3.up*Time.deltaTime*4);
3.控制子弹移动
transform.Translate (Vector3.up * Time.deltaTime * 10);
4.虚拟摇杆用的Untiy 里面 Standard Assets(Mobile).unityPackage自带的
5.碰撞检测代码
[csharp] view plaincopy
void OnTriggerEnter2D(Collider2D mCollider)
{
if ((mCollider.gameObject.tag == "Enemy"&&gameObject.tag=="GOOD")||(mCollider.gameObject.tag == "Player"&&gameObject.tag=="BAD"))
{
Destroy(mCollider.gameObject);
Destroy(this.gameObject);
if(gameObject.tag=="BAD")
{
PlayerPrefs.SetString("key","OVER");
Application.LoadLevel(1);
}
}
}
如果你发现有什么不合理的,需要改进的地方,请留言。
http://blog.csdn.net/xiaoxiao108/article/details/37882295