valera_za Дата: Пятница, 09 Сентября 2016, 18:22 | Сообщение # 1
участник
Сейчас нет на сайте
помогите со скриптамиДобавлено (09 сентября 2016, 17:54) --------------------------------------------- c# игра для андроид UnityДобавлено (09 сентября 2016, 18:22) --------------------------------------------- ладно Привет всем делаю игру на андроид, есть два персонажа (шарики),жизнь одна на двоих, жизни на шарике №1(полоска gui итд), второй устроен так что передает первому при контакте oncollision шарику №1 информацию о столкновении и у первого жизни утекают, собственно т.к жизнь одна,все бы хорошо в смысле переиграть еще раз ,но вот game over както не работает на шаре№2,на 1-ом работает ...не знаю лучший ли это способ, но вроде как все готово... 1 скрипт на первом шарике
Код
using UnityEngine; using System.Collections; public class LoadPrefs : MonoBehaviour { // Use this for initialization void Start () { PlayerPrefs.SetInt("life", 0); PlayerPrefs.SetInt("LifeCount", 0); } }
2 скрипт на 1 шарике
Код
using UnityEngine; using UnityEngine.UI; using System.Collections; public class Hero : MonoBehaviour { public GameObject pause;//new public GameObject pLost; public GameObject pWin; public int rand, count; public bool next, lose; public float rCol, gCol, bCol; public Text score; public bool paused; public GameObject other;//откл скрипт Таймер public GameObject[] gr; public GameObject[] st; public GameObject[] b_paus; public Animator herolose; public Animator herowin; public bool l; public bool a; public Heroball2 ro; //public Heroball2 ro; //public Sprite t, t2; public Animator t; //public AnimationClip M; //public WrapMode wrapMode; // Use this for initialization void Start () { l = false; herolose = GetComponent<Animator <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ); herowin = GetComponent<Animator <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ); t = GetComponent<Animator <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ); Time.timeScale = 1;//время идет next = false; lose = false; } // Update is called once per frame void Update () { if (lose) playerLose (); if (next && !lose) playerWin (); } void playerLose () { pLost.SetActive(true); if (PlayerPrefs.GetString ("Music") == "no") pLost.GetComponent <AudioSource <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).mute = false; other = GameObject.Find ("Cube");//откл скрипт Таймер Timer scr = other.GetComponent<Timer <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> );//откл скрипт Таймер scr.enabled=false;//откл скрипт Таймер GameObject [] gr = GameObject.FindGameObjectsWithTag("green"); foreach (GameObject go in gr) { go.GetComponent<Collider2D <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).enabled = false; //enabled =false; } GameObject [] st = GameObject.FindGameObjectsWithTag("star"); foreach (GameObject go in st) { go.GetComponent<Collider2D <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).enabled = false; } GameObject [] b_paus = GameObject.FindGameObjectsWithTag("pause"); foreach (GameObject go in b_paus) { go.GetComponent<Collider2D <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).enabled = false; } herolose.Play("herolose"); ro.blacklose.Play("blacklose"); Time.timeScale = 0; } void playerWin () { pWin.SetActive(true);// if (PlayerPrefs.GetString ("Music") == "no")// pWin.GetComponent <AudioSource <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).mute = false;// paused = false;// other = GameObject.Find ("Cube"); Timer scr = other.GetComponent<Timer <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ); scr.enabled=false; GameObject [] gr = GameObject.FindGameObjectsWithTag("green"); foreach (GameObject go in gr) { go.GetComponent<Collider2D <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).enabled = false; } GameObject [] st = GameObject.FindGameObjectsWithTag("star"); foreach (GameObject go in st) { go.GetComponent<Collider2D <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).enabled = false; } GameObject [] b_paus = GameObject.FindGameObjectsWithTag("pause"); foreach (GameObject go in b_paus) { go.GetComponent<Collider2D <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).enabled = false; } herowin.Play("herowin"); ro.blackwin.Play("blackwin"); Time.timeScale = 0; } void OnCollisionEnter2D(Collision2D col){ if (col.gameObject.tag == "win") playerWin ();// if (col.gameObject.tag == "border") playerLose (); } void OnMouseDown () { t.Play("t"); } void OnMouseUp () { } //public void pause () }
3 скрипт на 1 шарике
Код
using UnityEngine; using System.Collections; public class Life : MonoBehaviour { public int life = 3; public Texture fon; public Texture ramp; public Texture lifebar; public Texture onelife; public int LifeСount = 1; public GUISkin mySkin; public bool Visible = true; public GameObject pLost; public GameObject pGame_over; public GameObject other;//откл скрипт Таймер // Use this for initialization void Start () { GetComponent <Life <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).life = PlayerPrefs.GetInt ("LifeСount", life); } // Update is called once per frame void Update () { } void OnCollisionEnter2D(Collision2D c ){ if (c.gameObject.tag != "border") { return; } if ((life -= 1) <= 0) { if ((LifeСount -= 1) <= 0){ if ((life = 0) <= 0){ (Visible)= false; if ((LifeСount = 0) <= 0){ if (PlayerPrefs.HasKey("life")){ PlayerPrefs.DeleteKey("life"); PlayerPrefs.DeleteAll(); PlayerPrefs.Save(); } if ((LifeСount = 0) <= 0) if (PlayerPrefs.HasKey("LifeСount")){ PlayerPrefs.DeleteKey("LifeСount"); PlayerPrefs.DeleteAll(); PlayerPrefs.Save(); }else{ life = 3; } other = GameObject.Find ("Cube"); Timer scr = other.GetComponent<Timer <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ); scr.enabled=false;//откл скрипт Таймер Time.timeScale = 0; pLost.SetActive(false); pGame_over.SetActive(true); if (PlayerPrefs.GetString ("Music") == "no") pGame_over.GetComponent <AudioSource <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).mute = false; } } } } } void OnGUI (){ if(Visible) { GUI.skin = mySkin; GUI.Box(new Rect(20,10,60,18), " ", GUI.skin.GetStyle("fon")); GUI.Box(new Rect(20,10,60,18), " ", GUI.skin.GetStyle("ramp")); GUI.Box(new Rect(20,10,20 *life , 18), " ", GUI.skin.GetStyle("lifebar")); PlayerPrefs.SetInt("LifeСount", life); PlayerPrefs.GetInt("LifeСount", life); GUI.Box(new Rect(0,0 ,30,30), " ", GUI.skin.GetStyle("onelife")); } } }
на втором шарике 1 скрипт
Код
using UnityEngine; using System.Collections; public class Heroball2 : MonoBehaviour { public GameObject pLost; public GameObject pWin; public bool next,lose; public GameObject other;//откл скрипт Таймер public GameObject[] gr; public GameObject[] st; public Animator blacklose; public Animator blackwin; public bool l; public bool w; public bool paused; public Hero h; public Animator t2; // Use this for initialization void Start () { l = false; blacklose = GetComponent<Animator <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ); blackwin = GetComponent<Animator <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ); t2 = GetComponent<Animator <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ); Time.timeScale = 1; next = false; lose = false; } // Update is called once per frame void Update () { if (lose) playerLose (); if (next && !lose) playerWin (); } void playerLose () { pLost.SetActive(true); if (PlayerPrefs.GetString ("Music") == "no") pLost.GetComponent <AudioSource <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).mute = false; other = GameObject.Find ("Cube");//откл скрипт Таймер Timer scr = other.GetComponent<Timer <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> );//откл скрипт Таймер scr.enabled=false;//откл скрипт Таймер GameObject [] gr = GameObject.FindGameObjectsWithTag("green"); foreach (GameObject go in gr) { go.GetComponent<Collider2D <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).enabled = false; //enabled =false; } GameObject [] st = GameObject.FindGameObjectsWithTag("star"); foreach (GameObject go in st) { go.GetComponent<Collider2D <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).enabled = false; //enabled =false; } blacklose.Play("blacklose"); h.herolose.Play("herolose"); //blacklose.SetBool("blacklose", true ); Time.timeScale = 0; } void playerWin () { pWin.SetActive(true);// выгрыш if (PlayerPrefs.GetString ("Music") == "no")// pWin.GetComponent <AudioSource <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).mute = false; paused = false;//моя реализация отключения времени other = GameObject.Find ("Cube"); Timer scr = other.GetComponent<Timer <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ); scr.enabled=false; GameObject [] gr = GameObject.FindGameObjectsWithTag("green"); foreach (GameObject go in gr) { go.GetComponent<Collider2D <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).enabled = false; //enabled =false; } GameObject [] st = GameObject.FindGameObjectsWithTag("star"); foreach (GameObject go in st) { go.GetComponent<Collider2D <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).enabled = false; //enabled =false; } GameObject [] b_paus = GameObject.FindGameObjectsWithTag("pause"); foreach (GameObject go in b_paus) { go.GetComponent<Collider2D <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).enabled = false; //enabled =false; } blackwin.Play("blackwin"); h.herowin.Play("herowin"); //blackwin.SetBool("blackwin", true ); Time.timeScale = 0; } void OnCollisionEnter2D(Collision2D col){ if (col.gameObject.tag == "hero") playerWin (); //GameObject.Find("heroidle_0").GetComponent<Hero <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).pWin.SetActive(true); if (col.gameObject.tag == "border") playerLose (); //GameObject.Find("heroidle_0").GetComponent<Hero <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=" <img rel="usm" src="/SML/angry.gif" border="0" align="absmiddle" alt=">(" /> " /> " /> " /> " /> " /> " /> ).pLost.SetActive(true); } void OnMouseDown () { t2.Play ("t2"); } }
и еще раз на 2 ом шарике скрипт
Код
using UnityEngine; using System.Collections; public class Life_ball : MonoBehaviour { public int life = 3; public int LifeСount = 1; //public bool Visible = true; //public GameObject pLost2; //public GameObject pGame_over2; //public GameObject other; //public Life preplay; //public Life gameower; // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void OnCollisionEnter2D(Collision2D b ){ //if (b.gameObject.tag != "border") { return; } if (b.gameObject.tag != "border"){ return; } if ((life -= 1) <= 0) { GameObject.Find ("heroidle_0").GetComponent<Life> ().life -=1; if ((LifeСount -= 1) <= 0) { GameObject.Find ("heroidle_0").GetComponent<Life> ().LifeСount -=1; if ((life = 0) <= 0) { //както тут должно быть с 1ого скрипа брать pGame_over if ((LifeСount = 0) <= 0) { if (PlayerPrefs.HasKey ("life")) { PlayerPrefs.DeleteKey ("life"); PlayerPrefs.DeleteAll ();// PlayerPrefs.Save (); } if ((LifeСount = 0) <= 0) if (PlayerPrefs.HasKey ("LifeСount")) { PlayerPrefs.DeleteKey ("LifeСount"); PlayerPrefs.DeleteAll (); PlayerPrefs.Save (); } else {life =3 ;} } } } } } }
в коде life =0, у второго шарика надо как то понять как сделать проигрыш как у первого помогите должно быть что то синхронного проигрыша,второй шарик не могу заставить проигрывать... gui шкала ползет назад ,или вообще не реагирует это после 3х ударов о "border" а надо game over!!!!! if ((life = 0) <= 0) { //както тут должно быть с 1ого скрипа брать pGame_over } проблема во втором шарике поведение на проигрыш должно быть как у первого шарика буду надеяться и ждать что хоть кто нибудь поймет и поможет... В общем получается не прошло и месяца ,и все таки реализовал! все так как и было задумано...!!!фуф...
Сообщение отредактировал valera_za - Понедельник, 03 Октября 2016, 09:05