最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Unity實現(xiàn)打磚塊游戲

 更新時間:2022年05月11日 14:41:09   作者:大聰明深夜a題  
這篇文章主要為大家詳細介紹了Unity實現(xiàn)打磚塊游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Unity實現(xiàn)打磚塊游戲的具體代碼,供大家參考,具體內(nèi)容如下

效果演示

1.創(chuàng)建墻

1.1我們用預(yù)制體來統(tǒng)一管理墻

方便以后對墻進行修改

1.2我們還需要給磚塊一個剛體組件(物理屬性),不然墻就固定在那里不動。

1.3 把磚塊弄出來 再弄成一堵墻

2.發(fā)射子彈

我們將子彈也用預(yù)制體的方式創(chuàng)造。

這時就到了我們寫代碼的時候了。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
?
public class shoot : MonoBehaviour
{
? ? public GameObject bullet;//定義游戲物體 (子彈)
? ? float speed = 30;//子彈速度
? ? // Start is called before the first frame update
? ? void Start()
? ? {
? ? ? ?
? ? }
?
? ? // Update is called once per frame
? ? void Update()
? ? {
? ? ? ? if(Input.GetMouseButtonDown(0))//是否按下鼠標左鍵
? ? ? ? {
? ? ? ? ? ??
? ? ? ? ? ?GameObject b=GameObject.Instantiate(bullet,transform.position,transform.rotation);//生成子彈的位置
? ? ? ? ? ? Rigidbody rd = b.GetComponent<Rigidbody>();//得到生成子彈的剛體組件
? ? ? ? ? ? rd.velocity = transform.forward * speed;//為子彈施加速度
? ? ? ? }
? ? }
}

將這段代碼給攝像機就可以在運行游戲時按下鼠標左鍵發(fā)射子彈

3.移動發(fā)射

將以下腳本代碼給攝像機就可以完成移動了

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
?
public class hv: MonoBehaviour
{
? ? // Start is called before the first frame update
? ? void Start()
? ? {
? ? ? ??
? ? }
?
? ? // Update is called once per frame
? ? void Update()
? ? {
? ? ? ? float h=Input.GetAxis("Horizontal");//水平方向
? ? ? ? float v = Input.GetAxis("Vertical");//垂直方向
? ? ? ? transform.Translate(new Vector3(h, v, 0)/60);//移動速度
? ? }
}

4.檢驗

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

河北区| 新巴尔虎右旗| 临西县| 洪泽县| 嘉荫县| 饶阳县| 阳高县| 梅河口市| 淳安县| 海门市| 扎鲁特旗| 绥芬河市| 海宁市| 托克逊县| 都匀市| 云和县| 旅游| 福海县| 剑河县| 泰州市| 天祝| 弥渡县| 太和县| 遵义市| 长岭县| 宁明县| 密云县| 桃源县| 南和县| 武陟县| 大荔县| 兰溪市| 自治县| 泾阳县| 江西省| 库尔勒市| 繁峙县| 新乡市| 炉霍县| 麦盖提县| 大石桥市|