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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

Unity 游戏皇家消消乐Android版

發(fā)布時間:2024/1/1 Android 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Unity 游戏皇家消消乐Android版 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

下載地址工程
先來看一下運(yùn)行之后的效果圖




素材包大家可以下載工程,工程里面都有!會需要導(dǎo)入一個iTween的插件
場景的搭建我就不做過多的介紹了,每個人有自己喜歡的場景!
看一下!CameController.cs完成整個游戲的控制

using UnityEngine; using System.Collections; using UnityEngine.UI; public class CameController : MonoBehaviour {public GemStone gemstone;public int rowNum = 10;//列public int coluNum = 7;//行public ArrayList gamestonrlist;//存儲游戲物體的列表private GemStone currentgemstone;//保存當(dāng)前點擊private ArrayList mathesgemstone;//相同寶石的數(shù)組public ArrayList MidGemstonelist;//取得中間位置的行和列的寶石/// <summary>/// 三種聲音/// </summary>public AudioClip mathesClip;//消除之后的聲音public AudioClip swapclip;//物體交換的聲音public AudioClip errorclip;//不能交換的聲音static float EnergButton;//表示當(dāng)技能欄充滿的時候// Use this for initializationvoid Start () {gamestonrlist = new ArrayList ();mathesgemstone = new ArrayList ();MidGemstonelist = new ArrayList ();for (int rowindex=0; rowindex<rowNum; rowindex++) {ArrayList temp = new ArrayList();for(int coluindex=0;coluindex<coluNum;coluindex++){GemStone c = AddGemstone(rowindex,coluindex);//生成一行寶石,將行添加到temp里面!temp.Add(c);}gamestonrlist.Add(temp);//將所有的行添加到gamestonelist里面。}if (CheckHorizontalMatches () || CheckVerticalMathces ()) {RemoveMathes(); }}// Update is called once per framevoid Update () {}public GemStone AddGemstone(int rowindex,int coluindex)//生成寶石{GemStone c = Instantiate (gemstone) as GemStone;//強(qiáng)制裝換c.transform.parent = this.transform;c.GetComponent<GemStone>().RandomCreateGemstone();c.GetComponent<GemStone>().UpdatePosition(rowindex,coluindex);return c;}public void Select(GemStone c){if (currentgemstone == null) {currentgemstone = c;currentgemstone.isSelectd = true;return;} else {if((Mathf.Abs(currentgemstone.rowIndex-c.rowIndex)+Mathf.Abs(currentgemstone.clouIndex-c.clouIndex))==1){//ExangeAndMatches(currentgemstone,c);StartCoroutine(ExangeAndMatches(currentgemstone,c));//協(xié)程的調(diào)用}else{audio.PlayOneShot(errorclip);}currentgemstone.isSelectd = false;currentgemstone=null;//不能多次交換}}//協(xié)程IEnumerator ExangeAndMatches(GemStone c1,GemStone c2)//實現(xiàn)交換監(jiān)測行和列是否有相同的寶石{Change (c1, c2);yield return new WaitForSeconds (0.5f);if (CheckHorizontalMatches () || CheckVerticalMathces ()) {RemoveMathes ();} else {Debug.Log("沒有檢測到相同的寶石,交換回來");Change (c1, c2);}}void AddMathes(GemStone c){if (mathesgemstone == null) {mathesgemstone = new ArrayList(); }int index = mathesgemstone.IndexOf (c);//檢測該寶石是否已經(jīng)存在數(shù)組中if (index == -1) {mathesgemstone.Add(c);}}void AddMidMathes(GemStone c)//找到中間一行的寶石,和中間一列的寶石{if (MidGemstonelist == null) {MidGemstonelist = new ArrayList(); }int index = MidGemstonelist.IndexOf (c);//檢測是否在列表中if (index == -1) {MidGemstonelist.Add(c); }}void RemoveMathes()//消除相同的寶石{for (int i=0; i<mathesgemstone.Count; i++) {GemStone c = mathesgemstone[i] as GemStone;RemoveGemstone(c);}GameObject.FindGameObjectWithTag ("score").GetComponent<ScoreScript> ().Score+=1;//實現(xiàn)消失了一組之后再增加分?jǐn)?shù)EnergButton=GameObject.FindGameObjectWithTag ("energline").GetComponent<Scrollbar> ().value+=0.1f;if (GameObject.FindGameObjectWithTag ("score").GetComponent<ScoreScript> ().Score%50==0) {GameObject.FindGameObjectWithTag ("ExScore").GetComponent<ScoreScript> ().Score+=1; Application.LoadLevel ("GameStart");}Debug.Log(EnergButton);Energ ();mathesgemstone = new ArrayList ();StartCoroutine (WaitForCheckMathesAgain ());}/// <summary>/// 消除中間的寶石/// </summary>void RemoveMid(){for (int i=0; i<MidGemstonelist.Count; i++) {GemStone c = MidGemstonelist[i] as GemStone;RemoveGemstone(c);}GameObject.FindGameObjectWithTag ("score").GetComponent<ScoreScript> ().Score+=20;//實現(xiàn)消失了一組之后再增加分?jǐn)?shù)MidGemstonelist = new ArrayList ();StartCoroutine (WaitForCheckMathesAgain ());//重新檢測行和列有沒有相同的}public void Energ()//當(dāng)技能欄釋放完之后進(jìn)行的動作,改變技能提示按鈕的顏色{if (EnergButton >= 1.0f) {GameObject.FindGameObjectWithTag("EnergButton").GetComponent<Image>().color = Color.green;GameObject.FindGameObjectWithTag("Skill").GetComponent<MeshRenderer>().enabled = true;GameObject.FindGameObjectWithTag("Skill").GetComponent<SkillAnimation>().enabled = true;//EnergRelease();}}public void EnergRelease(){if (EnergButton >= 1.0f) {GameObject.FindGameObjectWithTag ("score").GetComponent<ScoreScript> ().Score += 20;//實現(xiàn)消失了一組之后再增加分?jǐn)?shù)EnergButton = GameObject.FindGameObjectWithTag ("energline").GetComponent<Scrollbar> ().value = 0.0f;GameObject.FindGameObjectWithTag("EnergButton").GetComponent<Image>().color = Color.white;GameObject.FindGameObjectWithTag("Skill").GetComponent<MeshRenderer>().enabled = false ;GameObject.FindGameObjectWithTag("Skill").GetComponent<SkillAnimation>().enabled = false ;} else {GameObject.FindGameObjectWithTag ("score").GetComponent<ScoreScript> ().Score += 0;//實現(xiàn)消失了一組之后再增加分?jǐn)?shù)}}public void SecendStart(){Application.LoadLevel ("GameStart");}IEnumerator WaitForCheckMathesAgain(){yield return new WaitForSeconds (0.5f);if (CheckHorizontalMatches () || CheckVerticalMathces ()) {RemoveMathes(); }}void RemoveGemstone(GemStone c)//實現(xiàn)刪除寶石{//Debug.Log("刪除");c.DisPose ();audio.PlayOneShot (mathesClip);for(int i=c.rowIndex+1;i<rowNum;i++){GemStone tempGemstone = Getgemstone(i,c.clouIndex);tempGemstone.rowIndex--;Setgemstone(tempGemstone.rowIndex,tempGemstone.clouIndex,tempGemstone);//tempGemstone.UpdatePosition(tempGemstone.rowIndex,tempGemstone.clouIndex);tempGemstone.TweenPOsition(tempGemstone.rowIndex,tempGemstone.clouIndex);}GemStone newGemstone = AddGemstone (rowNum,c.clouIndex);newGemstone.rowIndex--;Setgemstone (newGemstone.rowIndex,newGemstone.clouIndex,newGemstone);//newGemstone.UpdatePosition (newGemstone.rowIndex,newGemstone.clouIndex);newGemstone.TweenPOsition(newGemstone.rowIndex,newGemstone.clouIndex);}bool CheckHorizontalMatches(){bool isMathces = false;for (int rowIndex=0; rowIndex<rowNum; rowIndex++) {for(int coluIndex=0;coluIndex<coluNum-2;coluIndex++){if((Getgemstone(rowIndex,coluIndex).gemstontype==Getgemstone(rowIndex,coluIndex+1).gemstontype)&&(Getgemstone(rowIndex,coluIndex).gemstontype==Getgemstone(rowIndex,coluIndex+2).gemstontype)){Debug.Log("發(fā)現(xiàn)行相同的寶石");AddMathes(Getgemstone(rowIndex,coluIndex));AddMathes(Getgemstone(rowIndex,coluIndex+1));AddMathes(Getgemstone(rowIndex,coluIndex+2));isMathces = true;}}}return isMathces;}bool MidRowMathes()//中間位置行的寶石{bool isMidMathes = false;AddMidMathes(Getgemstone(0,0)); AddMidMathes(Getgemstone(0,1));AddMidMathes(Getgemstone(0,2));isMidMathes = true;return isMidMathes;}bool MidColuMathes()//中間位置列的寶石{bool isMidMathes = false;AddMidMathes(Getgemstone(2,5));AddMidMathes(Getgemstone(1,0));AddMidMathes(Getgemstone(2,0));isMidMathes =true; return isMidMathes;}bool CheckVerticalMathces(){bool isMathces = false;for(int coluIndex=0; coluIndex<coluNum; coluIndex++) {for (int rowIndex=0; rowIndex<rowNum-2; rowIndex++){if((Getgemstone(rowIndex,coluIndex).gemstontype==Getgemstone(rowIndex+1,coluIndex).gemstontype)&& (Getgemstone(rowIndex,coluIndex).gemstontype==Getgemstone(rowIndex+2,coluIndex).gemstontype)){Debug.Log("發(fā)現(xiàn)列相同的寶石");AddMathes(Getgemstone(rowIndex,coluIndex));AddMathes(Getgemstone(rowIndex+1,coluIndex));AddMathes(Getgemstone(rowIndex+2,coluIndex));isMathces = true;}}}return isMathces;}public GemStone Getgemstone(int rowindex,int coluindex)//通過行號列號取得對應(yīng)位置的寶石{ArrayList temp = gamestonrlist [rowindex] as ArrayList;GemStone c = temp [coluindex] as GemStone;return c;}public void Setgemstone(int rowindex,int coluindex,GemStone c)//設(shè)置所對應(yīng)行號列號對應(yīng)的寶石{ArrayList temp = gamestonrlist [rowindex] as ArrayList;temp [coluindex] = c;}public void Change(GemStone c1,GemStone c2)//實現(xiàn)交換{audio.PlayOneShot (swapclip);Setgemstone (c1.rowIndex,c1.clouIndex,c2);Setgemstone (c2.rowIndex,c2.clouIndex,c1);//交換c1 c2行號int tempRowIndex;tempRowIndex = c1.rowIndex;c1.rowIndex = c2.rowIndex;c2.rowIndex = tempRowIndex;int tempcoluINdex;tempcoluINdex = c1.clouIndex;c1.clouIndex = c2.clouIndex;c2.clouIndex = tempcoluINdex;//c1.UpdatePosition (c1.rowIndex, c1.clouIndex);c1.TweenPOsition (c1.rowIndex, c1.clouIndex);//c2.UpdatePosition (c2.rowIndex, c2.clouIndex);c2.TweenPOsition (c2.rowIndex, c2.clouIndex);} }

GameStone.cs的代碼 游戲物體的代碼

using UnityEngine; using System.Collections;public class GemStone : MonoBehaviour {public float xoffset = -4.8f;public float yoffset = -2f;public int rowIndex=0;public int clouIndex=0;public GameObject[] gemstonebgs;//寶石數(shù)組public int gemstontype;//寶石類型private GameObject gemastoneBg;public SpriteRenderer spriteRenderer;public bool isSelectd{set{if(value){spriteRenderer.color = Color.red;}else{spriteRenderer.color = Color.white;}}}public CameController cameController;// Use this for initializationvoid Awake(){}void Start () {cameController = GameObject.Find ("GameCortoller").GetComponent<CameController> ();spriteRenderer = gemastoneBg.GetComponent<SpriteRenderer> ();}// Update is called once per framevoid Update () {}public void UpdatePosition(int _rowIndex,int _coluIndex)//沒有特效的下落特效{rowIndex = _rowIndex;clouIndex = _coluIndex;this.transform.position = new Vector3 (clouIndex+xoffset, rowIndex+yoffset, 0);}public void TweenPOsition(int _rowIndex,int _coluIndex)//當(dāng)消除之后的插件特效{rowIndex = _rowIndex;clouIndex = _coluIndex;iTween.MoveTo (this.gameObject,iTween.Hash("x",clouIndex+xoffset,"y",rowIndex+yoffset,"time",0.4f));}public void RandomCreateGemstone()//生成隨機(jī)類型的寶石{if (gemastoneBg != null) {return; }gemstontype = Random.Range(0, gemstonebgs.Length);gemastoneBg = Instantiate(gemstonebgs[gemstontype]) as GameObject;gemastoneBg.transform.parent = this.transform;}public void OnMouseDown()//鼠標(biāo)點擊事件{cameController.Select (this);}public void DisPose()//釋放寶石!{Destroy (this.gameObject);Destroy (gemastoneBg.gameObject);cameController = null;} }

Backone.cs的代碼 用來支持andorid設(shè)備虛擬返回鍵

using UnityEngine; using System.Collections;public class BackOne : MonoBehaviour {// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {//android 鍵盤的虛擬返回鍵if(Input.GetKey(KeyCode.Escape)){Application.LoadLevel("Load");}} }

頁面跳轉(zhuǎn)之間的代碼EnergButtoncripts.cs

using UnityEngine; using System.Collections; using UnityEngine.UI; public class EnergButtonScript : MonoBehaviour {//游戲的鍵值類// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {}public void EnergClick(){CameController cameColtroller = new CameController ();cameColtroller.EnergRelease ();}public void Exit(){Application.LoadLevel ("Load");}public void ButtomRemove(){GameObject.FindGameObjectWithTag ("Gameover").GetComponent<RomoveBottom> ().isRomove = true;}/// <summary>/// /// /// /// </summary>public void SeStart()//重新開始{CameController c = new CameController ();c.SecendStart ();}public void Load(){Application.LoadLevel ("GameStart");}public void Explain(){Application.LoadLevel ("My");}public void Open(){Application.Quit ();}public void Back(){Application.LoadLevel ("Load");}public void Audio(){if (GameObject.FindGameObjectWithTag ("AudioText").GetComponent<Text> ().text == "Open") {PlayerPrefs.SetInt("Index",1);GameObject.FindGameObjectWithTag ("Audio").GetComponentInChildren<Text> ().text = "Close";print("1");}if (GameObject.FindGameObjectWithTag ("AudioText").GetComponent<Text> ().text == "Close") {PlayerPrefs.SetInt("Index",0);GameObject.FindGameObjectWithTag ("AudioText").GetComponent<Text> ().text = "Open";}} }

主界面菜單按鈕下落 RomoveButton.cs

using UnityEngine; using System.Collections; public class RomoveBottom : MonoBehaviour {public float RomoveSpeed = 1.5f;public bool isRomove = false;//在游戲開始界面進(jìn)行返回的按鈕!// Use this for initializationvoid Start () {}//-313// Update is called once per framevoid Update () {if (isRomove) {transform.Translate (-Vector3.up * RomoveSpeed);if (transform.localPosition.y <= -185) {RomoveSpeed = 0.0f;}}} }

Score.cs 分?jǐn)?shù)的腳本

using UnityEngine; using System.Collections; using UnityEngine.UI; public class ScoreScript : MonoBehaviour {//分?jǐn)?shù)的類public int Score=0;public int Experience=0;//關(guān)卡Text s;Text e;// Use this for initializationvoid Start () {s=transform.GetComponent<Text> ();e=transform.GetComponent<Text> ();}// Update is called once per framevoid Update () {s.text = Experience.ToString ();e.text = Score.ToString ();} }

退出游戲的腳本 Screen.cs

using UnityEngine; using System.Collections;public class Screen : MonoBehaviour {// Use this for initializationvoid Start () {}//退出整個游戲場景// Update is called once per framevoid Update () {if(Input.GetKey(KeyCode.Escape)){Application.Quit();}} }

動畫腳本 SkillAnimation.cs

using UnityEngine; using System.Collections;public class SkillAnimation : MonoBehaviour {//當(dāng)經(jīng)驗條滿格的時候,進(jìn)行技能輸出!int current;int count;float timer;public int fps=10;Object [] ani;public string path;// Use this for initializationvoid Start () {current = 0;ani = Resources.LoadAll("Image/"+path+"/img");count = ani.Length;}// Update is called once per framevoid Update () {if (ani != null) {timer+=Time.deltaTime;if(timer>=1.0f/fps){timer=0;current++;if(current>count-1){current=0;}this.renderer.material.mainTexture = (Texture2D)ani[current];}}} }

總結(jié)

以上是生活随笔為你收集整理的Unity 游戏皇家消消乐Android版的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。