Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

pasar puntucion la sguiente escena

Iniciado por brok, Diciembre 02, 2015, 12:46:32 AM

Tema anterior - Siguiente tema
Bueno estoy trabajando en este script de un tutorial y anadido algunas cosas y me gustaria que alguien me ayudara a mejorarlo, si se puede.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class ScoreManager : MonoBehaviour
{
    public static int score;


    Text text;
    public static ScoreManager estadoScore;
    private string rutaAchivo;
    void Awake ()
    {
        rutaAchivo = Application.persistentDataPath + "/datos.dat";
        if (estadoScore == null)
        {
            estadoScore = this;
            DontDestroyOnLoad(gameObject);
           
        }
        else if (estadoScore != this)
        {
            Destroy(gameObject);
           
        }
       
        text = GetComponent <Text> ();
        score = 0;
    }

    void Start()
    {
        Cargar();
    }

    void Update ()
    {
        text.text = "Puntos: " + score;
    }

    void Cargar()
    {
        if (File.Exists(rutaAchivo))
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream flie = new FileStream(rutaAchivo, FileMode.Open);
            DatosAGuargar datos = (DatosAGuargar)bf.Deserialize(flie);
            score = datos.puntuacionmax;

            flie.Close();

        }
        else
        {
            score = 0;
        }

    }

    void Guardar()
    {
        BinaryFormatter bf = new BinaryFormatter();
        FileStream flie = new FileStream(rutaAchivo, FileMode.Create, FileAccess.ReadWrite);
        DatosAGuargar datos = new DatosAGuargar();
        datos.puntuacionmax = score;
        bf.Serialize(flie, datos);
        flie.Close();
    }
}
[Serializable]
class DatosAGuargar
{
    public int puntuacionmax;
   
}
 

Diciembre 03, 2015, 11:38:51 PM #1 Ultima modificación: Diciembre 03, 2015, 11:39:43 PM por brok
Como podría acceder a los datos y guardarlos que tendría que hacer.
using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class Puntos : MonoBehaviour {

    public static int score;
    Text text;
    public static Puntos estadoScore;
    private string rutaAchivo;

    void Awake()
    {
        text = GetComponentInChildren<Text>();
        score = 0;
        rutaAchivo = Application.persistentDataPath + "/datos.dat";
        if (estadoScore == null)
        {
            estadoScore = this;
            DontDestroyOnLoad(gameObject);
            Debug.Log("primer objeto");

        }
        else if (estadoScore != this)
        {
            Destroy(gameObject);
            Debug.Log("segundo objeto");

        }

       
    }
    void Start()
    {
       
    }
    void Update()
    {
        text.text = "Puntos: " + score;
    }

    public void Guardar()
    {
        BinaryFormatter bf = new BinaryFormatter();
        FileStream flie = File.Create(rutaAchivo);
        DatosAGuargar datos = new DatosAGuargar();
        datos.puntuacionmax = score;
        bf.Serialize(flie, datos);
        flie.Close();
    }
    public void Cargar()
    {
        if (File.Exists(rutaAchivo))
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream flie = File.Open(rutaAchivo, FileMode.Open);
            DatosAGuargar datos = (DatosAGuargar)bf.Deserialize(flie);
            score = datos.puntuacionmax;

            flie.Close();

        }
        else
        {
            score = 0;
        }

    }

}
[Serializable]
class DatosAGuargar
{
    public int puntuacionmax;

}
 
Solucionado.

Etiquetas: