當前位置:
首頁 >
Unity 游戏皇家消消乐Android版
發布時間:2024/1/1
46
豆豆
生活随笔
收集整理的這篇文章主要介紹了
Unity 游戏皇家消消乐Android版
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
下載地址工程
先來看一下運行之后的效果圖
素材包大家可以下載工程,工程里面都有!會需要導入一個iTween的插件
場景的搭建我就不做過多的介紹了,每個人有自己喜歡的場景!
看一下!CameController.cs完成整個游戲的控制
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;//寶石數組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)//當消除之后的插件特效{rowIndex = _rowIndex;clouIndex = _coluIndex;iTween.MoveTo (this.gameObject,iTween.Hash("x",clouIndex+xoffset,"y",rowIndex+yoffset,"time",0.4f));}public void RandomCreateGemstone()//生成隨機類型的寶石{if (gemastoneBg != null) {return; }gemstontype = Random.Range(0, gemstonebgs.Length);gemastoneBg = Instantiate(gemstonebgs[gemstontype]) as GameObject;gemastoneBg.transform.parent = this.transform;}public void OnMouseDown()//鼠標點擊事件{cameController.Select (this);}public void DisPose()//釋放寶石!{Destroy (this.gameObject);Destroy (gemastoneBg.gameObject);cameController = null;} }Backone.cs的代碼 用來支持andorid設備虛擬返回鍵
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");}} }頁面跳轉之間的代碼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;//在游戲開始界面進行返回的按鈕!// 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 分數的腳本
using UnityEngine; using System.Collections; using UnityEngine.UI; public class ScoreScript : MonoBehaviour {//分數的類public int Score=0;public int Experience=0;//關卡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 {//當經驗條滿格的時候,進行技能輸出!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];}}} }總結
以上是生活随笔為你收集整理的Unity 游戏皇家消消乐Android版的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shell脚本写出一个简单的猜价格游戏
- 下一篇: android+直播点赞,Android