日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

关于简单的打地鼠游戏开发总结

發布時間:2023/12/16 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于简单的打地鼠游戏开发总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


1.
鼠標點擊函數制作:

首先我們需要建立好背景圖,調整攝像機為正交模式,進入二維狀態,調整背景圖分辨率為適當大小。

制作鼠標點擊腳本思路為先點擊然后銷毀對象以下為函數

為此函數銷毀被鼠標點擊的對象Destroy(gameObject);

然后制作一個預制體,是地鼠被打的圖片,在地鼠被鼠標點擊后存在0.5s左右的時間顯示地鼠被打的圖片,代碼整體為:

using
System.Collections;

using
System.Collections.Generic;

using
UnityEngine;

public class S3 : MonoBehaviour

{

// Start is called before the first frame
update

void Start()

{

Destroy(gameObject, 0.5f);

}

// Update is called once per frame

void
Update()

{

}

}

掛在被打地鼠狀態身上即可

using
System.Collections;

using
System.Collections.Generic;

using
UnityEngine;

public class S2 : MonoBehaviour

{

// Start is called before the first frame
update

public
GameObject m_Prefab2;

void Start()

{

}

void
OnMouseDown()

{

Instantiate(m_Prefab2, transform.position, Quaternion.identity);

Destroy(gameObject);

}

}

掛在地鼠圖片上即可(地鼠圖片上必須掛上碰撞體組件)

2.
制作地鼠隨機在孔中出來函數和隨機生成地鼠

把兩張地鼠圖片都制作成預制體然后在地鼠預制體圖片身上掛上制作的隨機生成代碼如下:

using
System.Collections;

using
System.Collections.Generic;

using
UnityEngine;

public class CreateTarget : MonoBehaviour

{

public
GameObject m_Target;

void Start()

{

// Create();

InvokeRepeating(“Create”, 0, 0.5f);

}

void
Create()

{

Vector3 pos = Vector3.zero;

int id = 0;

id = Random.Range(1,13);

if(id==1)

pos = new
Vector3(-0.464f, 0.201f, 0);

if (id ==
2)

pos = new Vector3(-1.395f,

0.201f, 0);

if (id ==
3)

pos = new Vector3(0.531f, 0.201f, 0);

if (id ==
4)

pos = new Vector3(1.467f, 0.201f, 0);

if (id ==
5)

pos = new Vector3(-1.204f, -0.652f, 0);

if (id ==
6)

pos = new Vector3(-0.027f, -0.652f, 0);

if (id ==
7)

pos = new Vector3(1.199f, -0.652f, 0);

if (id ==
8)

pos = new Vector3(-1.5f, 0.927f, 0);

if (id ==
9)

pos = new Vector3(-0.838f, 0.927f, 0);

if (id ==
10)

pos = new Vector3(-0.049f, 0.927f, 0);

if (id ==
11)

pos = new Vector3(0.663f, 0.927f, 0);

if (id ==
12)

pos = new Vector3(1.34f, 0.927f, 0);

Instantiate(m_Target, pos, Quaternion.identity);

//Instantiate(m_Target,)

}

}

由于我的圖片是十二個洞口,于是最簡單的方法做了十二個id,用Random.Range函數隨機生成。

3.最后給兩張地鼠的預制體掛上音效即可。
如圖:
找到合適的音效

掛在合適的對象上

總結

以上是生活随笔為你收集整理的关于简单的打地鼠游戏开发总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。