Search Unity

Score and Highscore help

Discussion in 'Scripting' started by Louis-LCM, Jan 19, 2015.

  1. Louis-LCM

    Louis-LCM

    Joined:
    Aug 26, 2014
    Posts:
    59
    Can anyone help me ? I'm trying to make a score and highscore system ... but I really can't do this ... Idk why but nothing works ... my game has 2 game modes ... arcade and time trial ... Can any1 please do this for me ? Here are my scripts ...

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. //two scripts are made of the same kind with little changes, this one used in arcade mode scene and other textinstantiate1 is used in timetrial scene
    5.  
    6.  
    7. public class textinstantiate : MonoBehaviour {
    8.  
    9.     //a hell lot of prefabs are created for creating the illusion
    10.     //which are drag droped in this public text gameobject
    11.     public GameObject[] text;
    12.  
    13.     //a copy of each instantiated text object is added in this clone gameobject
    14.     GameObject[] clone;
    15.  
    16.     //this one is useless, if you wanna use the OnGUI for touch buttons, a commented code is added at the bottom
    17.     public GUIStyle[] styles;
    18.  
    19.     //just variables to for string comparision
    20.     string textcolor="q";
    21.     string color="p";
    22.     string c="z";
    23.     string txt="x";
    24.  
    25.     //public score guitext drag-n-dropped here
    26.     public GUIText score;
    27.  
    28.     //for scoring
    29.     int count=0;
    30.  
    31.     //pointer objects(blinking indicators on screen)
    32.     public GameObject w1, w2;
    33.  
    34.     //colors and text guitexture are grag-dropped here from the "game" named object in hierarchy
    35.     public GUITexture[] colors;
    36.     //colors guitexture from "common" gameobject are added here
    37.     public GUITexture[] common;
    38.  
    39.     bool flag=false;
    40.  
    41.     //button animations
    42.     public Animation[] anim;
    43.  
    44.     //other gameobject from hierarchy
    45.     public GameObject gameover, game, commongui;
    46.  
    47.     //gameover ui components
    48.     public GameObject[] gameovergui;
    49.     public Sprite[] gameovertouch;
    50.     public Sprite[] tempgameover;
    51.  
    52.     void Awake()
    53.     {
    54.         Time.timeScale=1;
    55.         PlayerPrefs.SetInt("timetrial", 0);
    56.         PlayerPrefs.SetInt("gameover", 0);
    57.         PlayerPrefs.Save();
    58.         foreach(Animation a in anim)
    59.         {
    60.             a.wrapMode=WrapMode.Once;
    61.         }
    62.  
    63.         //if not level 3 "common" gameobject is set to active else "game" gameobject is set to active from hierarchy
    64.         if(PlayerPrefs.GetInt("level")!=3)
    65.         {
    66.             commongui.SetActive(true);
    67.         }
    68.         else
    69.             game.SetActive(true);
    70.     }
    71.    
    72.     // Use this for initialization
    73.     void Start ()
    74.     {
    75.  
    76.         //instantiation of texts from invokerepeating function
    77.         if(PlayerPrefs.GetInt("level")==3)
    78.         {
    79.             InvokeRepeating("create", 0, 2f);
    80.         }
    81.         else
    82.             InvokeRepeating("create", 0, 1f);
    83.  
    84.  
    85.         //blinking of pointers through invokerepeating
    86.         InvokeRepeating("fun", 0, 1f);
    87.     }
    88.  
    89.     void fun()
    90.     {
    91.         if(flag)
    92.         {
    93.             w1.SetActive(false);
    94.             w2.SetActive(false);
    95.             flag=false;
    96.         }
    97.         else
    98.         {
    99.             w1.SetActive(true);
    100.             w2.SetActive(true);
    101.             flag=true;
    102.         }
    103.     }
    104.  
    105.     void create()
    106.     {
    107.         Instantiate(text[Random.Range(0, text.Length)], new Vector3(0, 4, 0), Quaternion.identity);
    108.         clone=GameObject.FindGameObjectsWithTag("text");
    109.        
    110.         foreach(GameObject g in clone)
    111.         {
    112.             g.transform.position=new Vector2(0, g.transform.position.y-2f);
    113.         }
    114.     }
    115.  
    116.  
    117.     //this function recives the values from "textcontrol script" via sendmessage function
    118.     void pickme(string str1)
    119.     {
    120.         if(PlayerPrefs.GetInt("level")==3)
    121.         {
    122.             textcolor=str1[0].ToString();
    123.             color=str1[1].ToString();
    124.             //Debug.Log(textcolor+"textcolor");
    125.             //Debug.Log(color+"color");
    126.         }
    127.         else
    128.             textcolor=str1;
    129.     }
    130.  
    131.     //destroying the instantiated text objects when buttons(color or text buttons from scene) are pressed at the right time
    132.     void remove()
    133.     {
    134.         clone=GameObject.FindGameObjectsWithTag("text");
    135.         foreach(GameObject g in clone)
    136.         {
    137.             if(g.transform.position.y==-2f)
    138.             {
    139.                 count++;
    140.                 Destroy(g);
    141.             }
    142.         }
    143.     }
    144.  
    145.     void Update()
    146.     {
    147.  
    148.         if(PlayerPrefs.GetInt("pause")==0)
    149.         {
    150.             Time.timeScale=1;
    151.         }
    152.  
    153.         //here you can see the implementation of touch control via two different methods...using input.touch and from input.mousebuttondown...
    154.         //each button in hierarchy represents a its color name or text name...which are assigned in the variables when touched
    155.         score.text=count+"";
    156.         if(PlayerPrefs.GetInt("level")==3)
    157.         {
    158.         if (Input.touchCount > 0)
    159.         {
    160.             for(int i = 0; i < Input.touchCount; i++)
    161.                 {
    162.                 Touch t = Input.GetTouch(i);
    163.                
    164.                 if (t.phase == TouchPhase.Began) {
    165.                     if (colors[0].HitTest(t.position, Camera.main)) {
    166.                             audio.Play();
    167.                             c="b";
    168.                             anim[0].Play();
    169.                     }
    170.                    
    171.                     if (colors[1].HitTest(t.position, Camera.main)) {
    172.                             audio.Play();
    173.                         c="c";
    174.                             anim[1].Play();
    175.                     }
    176.  
    177.                     if (colors[2].HitTest(t.position, Camera.main)) {
    178.                             audio.Play();
    179.                         c="g";
    180.                             anim[2].Play();
    181.                     }
    182.  
    183.  
    184.                     if (colors[3].HitTest(t.position, Camera.main)) {
    185.                             audio.Play();
    186.                         c="m";
    187.                             anim[3].Play();
    188.                     }
    189.  
    190.                     if (colors[4].HitTest(t.position, Camera.main)) {
    191.                             audio.Play();
    192.                         c="o";
    193.                             anim[4].Play();
    194.                     }
    195.  
    196.                     if (colors[5].HitTest(t.position, Camera.main)) {
    197.                             audio.Play();
    198.                         c="r";
    199.                             anim[5].Play();
    200.                     }
    201.  
    202.                     if (colors[6].HitTest(t.position, Camera.main)) {
    203.                             audio.Play();
    204.                         c="v";
    205.                             anim[6].Play();
    206.                     }
    207.  
    208.                     if (colors[7].HitTest(t.position, Camera.main)) {
    209.                             audio.Play();
    210.                         c="y";
    211.                             anim[7].Play();
    212.                     }
    213.                     if (colors[8].HitTest(t.position, Camera.main)) {
    214.                             audio.Play();
    215.                         txt="b";
    216.                             anim[8].Play();
    217.                     }
    218.                    
    219.                     if (colors[9].HitTest(t.position, Camera.main)) {
    220.                             audio.Play();
    221.                         txt="c";
    222.                             anim[9].Play();
    223.                     }
    224.                    
    225.                     if (colors[10].HitTest(t.position, Camera.main)) {
    226.                             audio.Play();
    227.                         txt="g";
    228.                             anim[10].Play();
    229.                     }
    230.                    
    231.                    
    232.                     if (colors[11].HitTest(t.position, Camera.main)) {
    233.                             audio.Play();
    234.                         txt="m";
    235.                             anim[11].Play();
    236.                     }
    237.                    
    238.                     if (colors[12].HitTest(t.position, Camera.main)) {
    239.                             audio.Play();
    240.                         txt="o";
    241.                             anim[12].Play();
    242.                     }
    243.                    
    244.                     if (colors[13].HitTest(t.position, Camera.main)) {
    245.                             audio.Play();
    246.                         txt="r";
    247.                             anim[13].Play();
    248.                     }
    249.                    
    250.                     if (colors[14].HitTest(t.position, Camera.main)) {
    251.                             audio.Play();
    252.                         txt="v";
    253.                             anim[14].Play();
    254.                     }
    255.                    
    256.                     if (colors[15].HitTest(t.position, Camera.main)) {
    257.                             audio.Play();
    258.                         txt="y";
    259.                             anim[15].Play();
    260.                     }
    261.                 }
    262.                 if (t.phase == TouchPhase.Ended) {
    263.                     // Stop all movement
    264.                     Debug.Log("touch ended");
    265.                     c="a";
    266.                 }
    267.             }
    268.         }
    269.         }
    270.  
    271.         if(Input.GetMouseButtonDown(0))
    272.         {
    273.  
    274.             Vector2 pos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
    275.             RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(pos), Vector2.zero);
    276.  
    277.  
    278.             if (common[0].HitTest(Input.mousePosition, Camera.main)) {
    279.                 audio.Play();
    280.                 txt="b";
    281.                 anim[16].Play();
    282.             }
    283.             if (common[1].HitTest(Input.mousePosition, Camera.main)) {
    284.                 audio.Play();
    285.                 txt="c";
    286.                 anim[17].Play();
    287.             }
    288.             if (common[2].HitTest(Input.mousePosition, Camera.main)) {
    289.                 audio.Play();
    290.                 txt="g";
    291.                 anim[18].Play();
    292.             }
    293.             if (common[3].HitTest(Input.mousePosition, Camera.main)) {
    294.                 audio.Play();
    295.                 txt="m";
    296.                 anim[19].Play();
    297.             }
    298.             if (common[4].HitTest(Input.mousePosition, Camera.main)) {
    299.                 audio.Play();
    300.                 txt="o";
    301.                 anim[20].Play();
    302.             }
    303.             if (common[5].HitTest(Input.mousePosition, Camera.main)) {
    304.                 audio.Play();
    305.                 txt="r";
    306.                 anim[21].Play();
    307.             }
    308.             if (common[6].HitTest(Input.mousePosition, Camera.main)) {
    309.                 audio.Play();
    310.                 txt="v";
    311.                 anim[22].Play();
    312.             }
    313.             if (common[7].HitTest(Input.mousePosition, Camera.main)) {
    314.                 audio.Play();
    315.                 txt="y";
    316.                 anim[23].Play();
    317.             }
    318.  
    319.             if (hit.collider.name=="home") {
    320.                 audio.Play();
    321.                 Application.LoadLevel("menu");
    322.                 hit.collider.gameObject.GetComponent<SpriteRenderer>().sprite=gameovertouch[0];
    323.             }
    324.             if (hit.collider.name=="restart") {
    325.                 audio.Play();
    326.                 Application.LoadLevel(Application.loadedLevel);
    327.                 hit.collider.gameObject.GetComponent<SpriteRenderer>().sprite=gameovertouch[1];
    328.             }
    329.         }
    330.        
    331.         if(Input.GetMouseButtonUp(0))
    332.         {
    333.             txt="a";
    334.             gameovergui[0].GetComponent<SpriteRenderer>().sprite=tempgameover[0];
    335.             gameovergui[1].GetComponent<SpriteRenderer>().sprite=tempgameover[1];
    336.         }
    337.        
    338. //        if(PlayerPrefs.GetInt("pause")==1)
    339. //        {
    340. //            //pause.transform.position=Vector2.Lerp(pause.transform.position, new Vector2(0, 0), Time.deltaTime*10);
    341. //            game.transform.position=Vector2.Lerp(game.transform.position, new Vector2(-20f, 0), Time.deltaTime*10);
    342. //            commongui.transform.position=Vector2.Lerp(game.transform.position, new Vector2(-20f, 0), Time.deltaTime*10);
    343. //        }
    344. //        if(PlayerPrefs.GetInt("pause")==0)
    345. //        {
    346. //            //pause.transform.position=Vector2.Lerp(pause.transform.position, new Vector2(1.5f, 0), Time.deltaTime*10);
    347. //            game.transform.position=Vector2.Lerp(game.transform.position, new Vector2(0, 0), Time.deltaTime*10);
    348. //            commongui.transform.position=Vector2.Lerp(game.transform.position, new Vector2(0, 0), Time.deltaTime*10);
    349. //        }
    350.        
    351.         if(PlayerPrefs.GetInt("gameover")==1)
    352.         {
    353.             gameover.transform.position=Vector2.Lerp(gameover.transform.position, new Vector2(0, 0), Time.deltaTime*10);
    354.             game.transform.position=Vector2.Lerp(game.transform.position, new Vector2(20f, 0), Time.deltaTime*10);
    355.             commongui.transform.position=Vector2.Lerp(game.transform.position, new Vector2(20f, 0), Time.deltaTime*10);
    356.  
    357.         }
    358.  
    359. //        if(PlayerPrefs.GetInt("gameover")==1 && !flag)
    360. //        {
    361. //            PlayerPrefs.SetInt("ad", PlayerPrefs.GetInt("ad")+1);
    362. //            PlayerPrefs.Save();
    363. //            if(PlayerPrefs.GetInt("ad")>2)
    364. //            {
    365. //                GoogleMobileAd.StartInterstitialAd();
    366. //                PlayerPrefs.SetInt("ad", 0);
    367. //                PlayerPrefs.Save();
    368. //            }
    369. //            Debug.Log(PlayerPrefs.GetInt("ad").ToString());
    370. //            flag=true;
    371. //        }
    372.        
    373.     }
    374.  
    375.  
    376.  
    377.     //main logic of the game, simple comparision of the strings are done to check the incoming instantiated text objects when they reach the blinking pointer
    378.     //this way it is checked if button color pressed and the instantiated text's color are same // this game is all illusion, i would recommend you to play it several times before going through scripts to understand it.
    379.     //even you dont learn the game u can learn touch controls and menu transitions from this
    380.     void FixedUpdate()
    381.     {
    382.         if(PlayerPrefs.GetInt("level")==3)
    383.         {
    384.             if(color.Equals(c) && textcolor.Equals(txt))
    385.             {
    386.                 remove();
    387.             }
    388.         }
    389.         else
    390.         {
    391.             if(textcolor.Equals(txt))
    392.             {
    393.                 remove();
    394.             }
    395.         }
    396.        
    397.     }
    398.    
    399. }
    400.  

    and ...


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4.  
    5. // this script is similar to the "textinstantiate" script only have a little changes...
    6. //everything you need know is decribed in another script
    7. public class textinstantiate1 : MonoBehaviour {
    8.  
    9.     public GameObject[] text;
    10.     GameObject[] clone;
    11.     public GUIStyle[] styles;
    12.     string textcolor="p";
    13.     string color="q";
    14.     public GUIText score, gtime;
    15.     int count=0;
    16.     public GameObject w1, w2;
    17.     bool flag=false;
    18.     string c="s";
    19.     string txt="t";
    20.     public GUITexture[] colors;
    21.     public Animation[] anim;
    22.     float time=31;
    23.     public GameObject gameover, pause, game, commongui;
    24.     public GameObject[] gameovergui;
    25.     public Sprite[] gameovertouch;
    26.     public Sprite[] tempgameover;
    27.     public GameObject[] pausegui;
    28.     public Sprite[] pausetouch;
    29.     public Sprite[] temppause;
    30.     public GUITexture[] common;
    31.     void Awake()
    32.     {
    33.         Time.timeScale=1;
    34.        
    35.         PlayerPrefs.SetInt("ad", PlayerPrefs.GetInt("ad")+1);
    36.         PlayerPrefs.SetInt("timetrial", 1);
    37.         PlayerPrefs.SetInt("gameover", 0);
    38.         PlayerPrefs.SetInt("pause", 2);
    39.         PlayerPrefs.Save();
    40.         foreach(Animation a in anim)
    41.         {
    42.             a.wrapMode=WrapMode.Once;
    43.         }
    44.         if(PlayerPrefs.GetInt("level")!=3)
    45.         {
    46.             commongui.SetActive(true);
    47.         }
    48.         else
    49.             game.SetActive(true);
    50.     }
    51.    
    52.     // Use this for initialization
    53.     void Start ()
    54.     {
    55.         if(PlayerPrefs.GetInt("level")==3)
    56.         {
    57.             InvokeRepeating("create", 0, 2f);
    58.         }
    59.         else
    60.             InvokeRepeating("create", 0, 1f);
    61.         InvokeRepeating("fun", 0, 1f);
    62.     }
    63.  
    64.     void fun()
    65.     {
    66.         if(flag)
    67.         {
    68.             w1.SetActive(false);
    69.             w2.SetActive(false);
    70.             flag=false;
    71.         }
    72.         else
    73.         {
    74.             w1.SetActive(true);
    75.             w2.SetActive(true);
    76.             flag=true;
    77.         }
    78.         if(PlayerPrefs.GetInt("gameover")!=1)
    79.         {
    80.             time--;
    81.             gtime.text=time.ToString();
    82.             Debug.Log(time.ToString());
    83.         }
    84.  
    85.  
    86.     }
    87.  
    88.     void create()
    89.     {
    90.         Instantiate(text[Random.Range(0, text.Length)], new Vector3(0, 4, 0), Quaternion.identity);
    91.         clone=GameObject.FindGameObjectsWithTag("text");
    92.        
    93.         foreach(GameObject g in clone)
    94.         {
    95.             g.transform.position=new Vector2(0, g.transform.position.y-2f);
    96.         }
    97.     }
    98.  
    99.     void pickme(string str1)
    100.     {
    101.         if(PlayerPrefs.GetInt("level")==3)
    102.         {
    103.             textcolor=str1[0].ToString();
    104.             color=str1[1].ToString();
    105.         }
    106.         else
    107.             textcolor=str1;
    108.     }
    109.  
    110.     void remove()
    111.     {
    112.         clone=GameObject.FindGameObjectsWithTag("text");
    113.         foreach(GameObject g in clone)
    114.         {
    115.             if(g.transform.position.y==-2f)
    116.             {
    117.                 count++;
    118.                 Destroy(g);
    119.             }
    120.         }
    121.     }
    122.  
    123.     void Update()
    124.     {
    125.  
    126.         if(PlayerPrefs.GetInt("pause")==0)
    127.         {
    128.             Time.timeScale=1;
    129.         }
    130.  
    131.         score.text=count+"";
    132.         if(PlayerPrefs.GetInt("level")==3)
    133.         {
    134.         if (Input.touchCount > 0)
    135.         {
    136.             for(int i = 0; i < Input.touchCount; i++)
    137.                 {
    138.                 Touch t = Input.GetTouch(i);
    139.                
    140.                 if (t.phase == TouchPhase.Began) {
    141.                         audio.Play();
    142.                     if (colors[0].HitTest(t.position, Camera.main)) {
    143.                             audio.Play();
    144.                         c="b";
    145.                             anim[0].Play();
    146.                     }
    147.                    
    148.                     if (colors[1].HitTest(t.position, Camera.main)) {
    149.                             audio.Play();
    150.                         c="c";
    151.                             anim[1].Play();
    152.                     }
    153.  
    154.                     if (colors[2].HitTest(t.position, Camera.main)) {
    155.                             audio.Play();
    156.                         c="g";
    157.                             anim[2].Play();
    158.                     }
    159.  
    160.  
    161.                     if (colors[3].HitTest(t.position, Camera.main)) {
    162.                             audio.Play();
    163.                         c="m";
    164.                             anim[3].Play();
    165.                     }
    166.  
    167.                     if (colors[4].HitTest(t.position, Camera.main)) {
    168.                             audio.Play();
    169.                         c="o";
    170.                             anim[4].Play();
    171.                     }
    172.  
    173.                     if (colors[5].HitTest(t.position, Camera.main)) {
    174.                             audio.Play();
    175.                         c="r";
    176.                             anim[5].Play();
    177.                     }
    178.  
    179.                     if (colors[6].HitTest(t.position, Camera.main)) {
    180.                             audio.Play();
    181.                         c="v";
    182.                             anim[6].Play();
    183.                     }
    184.  
    185.                     if (colors[7].HitTest(t.position, Camera.main)) {
    186.                             audio.Play();
    187.                         c="y";
    188.                             anim[7].Play();
    189.                     }
    190.                     if (colors[8].HitTest(t.position, Camera.main)) {
    191.                             audio.Play();
    192.                         txt="b";
    193.                             anim[8].Play();
    194.                     }
    195.                    
    196.                     if (colors[9].HitTest(t.position, Camera.main)) {
    197.                             audio.Play();
    198.                         txt="c";
    199.                             anim[9].Play();
    200.                     }
    201.                    
    202.                     if (colors[10].HitTest(t.position, Camera.main)) {
    203.                             audio.Play();
    204.                         txt="g";
    205.                             anim[10].Play();
    206.                     }
    207.                    
    208.                    
    209.                     if (colors[11].HitTest(t.position, Camera.main)) {
    210.                             audio.Play();
    211.                         txt="m";
    212.                             anim[11].Play();
    213.                     }
    214.                    
    215.                     if (colors[12].HitTest(t.position, Camera.main)) {
    216.                             audio.Play();
    217.                         txt="o";
    218.                             anim[12].Play();
    219.                     }
    220.                    
    221.                     if (colors[13].HitTest(t.position, Camera.main)) {
    222.                             audio.Play();
    223.                         txt="r";
    224.                             anim[13].Play();
    225.                     }
    226.                    
    227.                     if (colors[14].HitTest(t.position, Camera.main)) {
    228.                             audio.Play();
    229.                         txt="v";
    230.                             anim[14].Play();
    231.                     }
    232.                    
    233.                     if (colors[15].HitTest(t.position, Camera.main)) {
    234.                             audio.Play();
    235.                         txt="y";
    236.                             anim[15].Play();
    237.                     }
    238.                 }
    239.                 if (t.phase == TouchPhase.Ended) {
    240.                     // Stop all movement
    241.                     Debug.Log("touch ended");
    242.                     c="a";
    243.                 }
    244.             }
    245.         }
    246.         }
    247.  
    248.  
    249.         if(Input.GetMouseButtonDown(0))
    250.         {
    251.  
    252.             Vector2 pos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
    253.             RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(pos), Vector2.zero);
    254.  
    255.  
    256.             if (common[0].HitTest(Input.mousePosition, Camera.main)) {
    257.                 audio.Play();
    258.                 txt="b";
    259.                 anim[16].Play();
    260.             }
    261.             if (common[1].HitTest(Input.mousePosition, Camera.main)) {
    262.                 audio.Play();
    263.                 txt="c";
    264.                 anim[17].Play();
    265.             }
    266.             if (common[2].HitTest(Input.mousePosition, Camera.main)) {
    267.                 audio.Play();
    268.                 txt="g";
    269.                 anim[18].Play();
    270.             }
    271.             if (common[3].HitTest(Input.mousePosition, Camera.main)) {
    272.                 audio.Play();
    273.                 txt="m";
    274.                 anim[19].Play();
    275.             }
    276.             if (common[4].HitTest(Input.mousePosition, Camera.main)) {
    277.                 audio.Play();
    278.                 txt="o";
    279.                 anim[20].Play();
    280.             }
    281.             if (common[5].HitTest(Input.mousePosition, Camera.main)) {
    282.                 audio.Play();
    283.                 txt="r";
    284.                 anim[21].Play();
    285.             }
    286.             if (common[6].HitTest(Input.mousePosition, Camera.main)) {
    287.                 audio.Play();
    288.                 txt="v";
    289.                 anim[22].Play();
    290.             }
    291.             if (common[7].HitTest(Input.mousePosition, Camera.main)) {
    292.                 audio.Play();
    293.                 txt="y";
    294.                 anim[23].Play();
    295.             }
    296.  
    297.             if(time>1)
    298.             {
    299.                 if(hit.collider.name=="pausebg")
    300.                 {
    301.                     Invoke("farzi", .5f);
    302.                     PlayerPrefs.SetInt("pause", 1);
    303.                     PlayerPrefs.Save();
    304.                 }
    305.             }
    306.  
    307.             if (hit.collider.name=="home") {
    308.                 audio.Play();
    309.                 Application.LoadLevel("menu");
    310.                 hit.collider.gameObject.GetComponent<SpriteRenderer>().sprite=gameovertouch[0];
    311.             }
    312.             if (hit.collider.name=="restart") {
    313.                 audio.Play();
    314.                 Application.LoadLevel(Application.loadedLevel);
    315.                 hit.collider.gameObject.GetComponent<SpriteRenderer>().sprite=gameovertouch[1];
    316.             }
    317.             if(hit.collider.name=="resume_p")
    318.             {
    319.                 audio.Play();
    320.                 PlayerPrefs.SetInt("pause", 0);
    321.                 PlayerPrefs.SetInt("ad", PlayerPrefs.GetInt("ad")+1);
    322.                 PlayerPrefs.Save();
    323.                 hit.collider.gameObject.GetComponent<SpriteRenderer>().sprite=pausetouch[0];
    324.             }
    325.             if(hit.collider.name=="restart_p")
    326.             {
    327.                 audio.Play();
    328.                 Application.LoadLevel(Application.loadedLevel);
    329.                 hit.collider.gameObject.GetComponent<SpriteRenderer>().sprite=pausetouch[1];
    330.             }
    331.             if(hit.collider.name=="home_p")
    332.             {
    333.                 audio.Play();
    334.                 Application.LoadLevel("menu");
    335.                 hit.collider.gameObject.GetComponent<SpriteRenderer>().sprite=pausetouch[2];
    336.             }
    337.         }
    338.  
    339.         if(Input.GetMouseButtonUp(0))
    340.         {
    341.             txt="a";
    342.             gameovergui[0].GetComponent<SpriteRenderer>().sprite=tempgameover[0];
    343.             gameovergui[1].GetComponent<SpriteRenderer>().sprite=tempgameover[1];
    344.             pausegui[0].GetComponent<SpriteRenderer>().sprite=temppause[0];
    345.             pausegui[1].GetComponent<SpriteRenderer>().sprite=temppause[1];
    346.             pausegui[2].GetComponent<SpriteRenderer>().sprite=temppause[2];
    347.         }
    348.  
    349.         if(PlayerPrefs.GetInt("pause")==1)
    350.         {
    351.             pause.transform.position=Vector2.Lerp(pause.transform.position, new Vector2(0, 0), Time.deltaTime*10);
    352.             game.transform.position=Vector2.Lerp(game.transform.position, new Vector2(-20f, 0), Time.deltaTime*10);
    353.             commongui.transform.position=Vector2.Lerp(game.transform.position, new Vector2(-20f, 0), Time.deltaTime*10);
    354.         }
    355.         if(PlayerPrefs.GetInt("pause")==0)
    356.         {
    357.             pause.transform.position=Vector2.Lerp(pause.transform.position, new Vector2(20f, 0), Time.deltaTime*10);
    358.             game.transform.position=Vector2.Lerp(game.transform.position, new Vector2(0, 0), Time.deltaTime*10);
    359.             commongui.transform.position=Vector2.Lerp(game.transform.position, new Vector2(0, 0), Time.deltaTime*10);
    360.         }
    361.  
    362.         if(time==0)
    363.         {
    364.  
    365.             gameover.transform.position=Vector2.Lerp(gameover.transform.position, new Vector2(0, 0), Time.deltaTime*10);
    366.             game.transform.position=Vector2.Lerp(game.transform.position, new Vector2(20f, 0), Time.deltaTime*10);
    367.             commongui.transform.position=Vector2.Lerp(game.transform.position, new Vector2(20f, 0), Time.deltaTime*10);
    368.             //Invoke("farzi2", 1);
    369.             PlayerPrefs.SetInt("gameover", 1);
    370.         }
    371.  
    372.  
    373.     }
    374.  
    375.     //farzi is hindi word...means useless but this one is used
    376.     void farzi()
    377.     {
    378.         Time.timeScale=0;
    379.     }
    380.  
    381.     void FixedUpdate()
    382.     {
    383.         if(PlayerPrefs.GetInt("level")==3)
    384.         {
    385.             if(color.Equals(c) && textcolor.Equals(txt))
    386.             {
    387.                 remove();
    388.             }
    389.         }
    390.         else
    391.         {
    392.             if(textcolor.Equals(txt))
    393.             {
    394.                 remove();
    395.             }
    396.         }
    397.  
    398.     }
    399.  
    400. }
    401.  
     
  2. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    what's your game, gameplay, game mechanics? how and when does the player get points for doing what?
     
  3. Louis-LCM

    Louis-LCM

    Joined:
    Aug 26, 2014
    Posts:
    59
  4. Louis-LCM

    Louis-LCM

    Joined:
    Aug 26, 2014
    Posts:
    59
  5. Louis-LCM

    Louis-LCM

    Joined:
    Aug 26, 2014
    Posts:
    59
    No one can help me ?
     
  6. ldb

    ldb

    Joined:
    Apr 30, 2013
    Posts:
    40
    It's kind of bad etiquette to just outright ask someone to do something for you. And kind of lazy. And you've just dumped a couple of scripts on us without any explanation. And you haven't answered the questions another user asked you....

    Try to be a bit more specific. What exactly have you tried? What exactly are you having trouble with?

    No one in their right mind will bother to scour through 800 lines of code to try to figure what your issue is.
     
    AlucardJay likes this.
  7. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    downloaded it will have a look when i have time...
    btw the scripts you posted are giving me a slight headache ;-)
     
  8. Louis-LCM

    Louis-LCM

    Joined:
    Aug 26, 2014
    Posts:
    59
    Me too ....
     
  9. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,727
    If you have a game with a score and want to add a high score mechanism, you essentially need these parts, and you need to put them into the game in the appropriate spots:

    1. a storage mechanism to store the high score. I recommend PlayerPrefs.GetInt() and .SetInt()

    2. a display mechanism to show the high score on your front menu page (and maybe your in-game screen too)

    3. a comparison statement that is called after each game to compare the last score with the high score, and if it is higher, then update the storage mechanism in #1.

    Work on each part separately, and test it by debugging to make sure it works as expected.
     
    Louis-LCM likes this.
  10. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    hey Louis LCM,
    I had a look at you're game and i'm sorry to say that it is just too much spaghetti code, it would take too much time and energy just to figure out what's happening as opposed to rewriting your game.
    It's clear you have reached your limit in what you can code without thinking Object Oriented, my advice is to check out some basic C# tutorials on youtube and within a week or so make that same game again.
    everything will be so much clearer on how to handle your code and build your game...
     
    Louis-LCM likes this.
  11. Louis-LCM

    Louis-LCM

    Joined:
    Aug 26, 2014
    Posts:
    59
    Thank you anyway :D !