Unity打砖块小游戏制作过程
2020-03-22 07:26
585 查看
操作步骤
- 新建一个plane,修改位置坐标为(0,0,0)导入资源包, 新建一个空对象,命名为Wall,用于存放后面脚本生产的小方块
- 新建一个脚本,重命名为Brick,用于生成由Cube组成的墙。把脚本附给Wall,脚本复制对象选择资源包中的小方块的预制件
。脚本内容如下:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Brick : MonoBehaviour { public GameObject brick; private int columnNum=8;//列数 private int rowNum = 6;//行数 // Start is called before the first frame update void Start() { for(int i = 0; i < rowNum; i++) { for(int j = 0; j < columnNum; j++) { Instantiate(brick, new Vector3(j-5,i),Quaternion.identity); } } } // Update is called once per frame void Update() { } }
- 新建一个脚本文件,命名为shoot,用于生成发射的小球,将脚本附给Main Camrea,发射位置选择摄像机的位置,复制对象选择资源包中的小球的预制件,脚本内容如下:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Shoot : MonoBehaviour { public GameObject shootPosition; private float force = 1000; public Rigidbody shooter; private float cameraSpeed = 0.1f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { Rigidbody ball; if (Input.GetKeyDown(KeyCode.Space)) { ball = Instantiate(shooter, shootPosition.transform.position, Quaternion.identity) as Rigidbody; ball.AddForce(force * ball.transform.forward); } if (Input.GetKey(KeyCode.LeftArrow)) { this.transform.Translate(Vector3.left * cameraSpeed); } if (Input.GetKey(KeyCode.RightArrow)) { this.transform.Translate(Vector3.right * cameraSpeed); } if (Input.GetKey(KeyCode.UpArrow)) { this.transform.Translate(Vector3.up * cameraSpeed); } if (Input.GetKey(KeyCode.DownArrow)) { this.transform.Translate(Vector3.down * cameraSpeed); } } }
5. 制作完成
相关文章推荐
- 自制Unity小游戏TankHero-2D(1)制作主角坦克
- Unity2D 制作小游戏FlappyBird心得—Unity5学习笔记
- Unity中FPS类小游戏的简单制作
- 利用unity 制作贪吃蛇小游戏
- 【JS】js学习笔记之用canvas制作打砖块小游戏(未完成)
- Unity 2D 打地鼠游戏制作过程总结
- 自制Unity小游戏TankHero-2D(2)制作敌方坦克
- Cinema Director 教程——unity制作过程动画,剧情等
- Unity学习之打砖块小游戏
- Cinema Director 教程——unity制作过程动画,剧情等
- Unity-3D捕鱼达人小游戏开发 —— 游戏中精灵动画的制作
- unity学习之飞机大战制作 关键点(MAX) 成品小游戏飞机大战
- Unity IMGUI 的小游戏(井字棋)制作以及怎么发布为安卓apk并且发给女孩子手机上成功运行的教程 - 3D游戏编程学习日志
- C#制作、打包、签名、发布Activex全过程
- 用cocos2d 2.1制作一个过河小游戏(1): 总概
- Android中.9图片的了解和制作过程
- 如何中断Unity动画状态机的转换过程?
- Unity-3d Day05 打地鼠小游戏
- unity制作mmd视频
- 如何制作unity艺术字体