Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[UI 4.6] reload scene and keep variable.

Discussion in 'UGUI & TextMesh Pro' started by Lataits, Dec 3, 2014.

  1. Lataits

    Lataits

    Joined:
    Dec 3, 2014
    Posts:
    1
    Hello, first of all, sorry for my bad english :/

    Well, I have a little problem, i have a scene that gives a number(beetween 1,5) the first time i get on it, then implement it by 1 every time i push the button, i tried many different way like don't kill on load or using static variables but it does'nt do what i want , everytime i push the button it has the same behavior as it was the first time i push it.
    May you help me ?

    here are my codes.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class wichTeam : MonoBehaviour {
    6.  
    7.  
    8.        
    9.     private int i=0;
    10.     public bool first=true;
    11.     // Use this for initialization
    12.     void Start () {
    13.  
    14.     /*    GameObject gmco=GameObject.FindWithTag ("GameController");
    15.         gameController gc=gmco.GetComponent <gameController>();
    16. */
    17.         Text txt = GameObject.FindWithTag ("team").GetComponent<Text> ();
    18.         if (first==true) {
    19.             i = (int)Random.Range (1, 6);//gc.getNE () + 1);
    20.                         txt.text = "" + i;
    21.                         first = false;
    22.                 }
    23.         else {
    24.                         i=(i%6)+1;
    25.             txt.text = "" + i;
    26.                 }
    27.     }
    28.    
    29.  
    30. }
    31.  
    32.  
    and there the button behavior

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class tempButton : MonoBehaviour {
    6.    
    7.     public void Temporaire() {
    8.  
    9.         Application.LoadLevel (3);
    10.         GameObject Ars = GameObject.FindWithTag ("ars");
    11.         DontDestroyOnLoad (Ars);
    12.  
    13.    
    14.     }
    15.  
    16. }