Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        mobileSupport = mobileSupportScript.mobileSupport;
        speedstore    = speed;
        PV            = GetComponent <PhotonView>();
        TC            = GameObject.Find("GameCanvas").transform.GetChild(0).GetComponent <TimerControler>();
        if (PV.Owner.NickName != "")
        {
            UserNameText.text = PV.Owner.NickName;
        }
        else if (PV.IsMine)
        {
            UserNameText.text = "Player " + Random.Range(0, 1000);
            PV.RPC("SetNameRPC", RpcTarget.All, UserNameText.text);
        }

        if (!PV.IsMine)
        {
            Destroy(GetComponent <Rigidbody>());
            return;
        }
        Camera = Instantiate(cam);
        Camera.GetComponent <CameraFollow>().CameraFollowObj = transform.GetChild(0).gameObject;
        rb         = GetComponent <Rigidbody>();
        controller = GetComponent <CharacterController>();
        co.Add(StartCoroutine(check()));
        //TC.addToTotal(5);
        LJ = GameObject.Find("Left Joystick").GetComponent <LeftJoystick>();
    }
    /// <summary>
    /// Constructor with 3 parameters
    /// </summary>
    /// <param name="knight"> stores the knight position and scale </param>
    /// <param name="dragon"> stores the dragon position and scale </param>
    /// <param name="timerControler"> stores the elapsed time </param>
    public PlayersData(KnightControler knight, DragonControler dragon, TimerControler timerControler)
    {
        positionKnight    = new float[3];
        positionKnight[0] = knight.transform.localPosition.x;
        positionKnight[1] = knight.transform.localPosition.y;
        positionKnight[2] = knight.transform.localPosition.z;

        scaleKnight    = new float[3];
        scaleKnight[0] = knight.transform.localScale.x;
        scaleKnight[1] = knight.transform.localScale.y;
        scaleKnight[2] = knight.transform.localScale.z;

        positionDragon    = new float[3];
        positionDragon[0] = dragon.transform.localPosition.x;
        positionDragon[1] = dragon.transform.localPosition.y;
        positionDragon[2] = dragon.transform.localPosition.z;

        scaleDragon    = new float[3];
        scaleDragon[0] = dragon.transform.localScale.x;
        scaleDragon[1] = dragon.transform.localScale.y;
        scaleDragon[2] = dragon.transform.localScale.z;

        timer      = timerControler.GetStartTime();
        sceneIndex = SceneManager.GetActiveScene().buildIndex;
    }
    /// <summary>
    /// static function that performs the saving process, from current
    /// it builds a PlayersData object and serializes it in a persistent data path
    /// </summary>
    public static void SaveSystem(KnightControler knight, DragonControler dragon, TimerControler timerControler)
    {
        BinaryFormatter formatter = new BinaryFormatter();

        string     path   = Application.persistentDataPath + "/savefile.fun";
        FileStream stream = new FileStream(path, FileMode.Create);

        PlayersData data = new PlayersData(knight, dragon, timerControler);

        formatter.Serialize(stream, data);
        stream.Close();
    }