Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Bvv7070 · Jun 22, 2016 at 08:32 PM · unity 5scripting problem

I have error in my game saving script (C#).

this is error: Assets/Scripts/LoadGame.cs(48,2): error CS0246: The type or namespace name `serializable' could not be found. Are you missing a using directive or an assembly reference?

I want to know what's wrong.

 using UnityEngine;
 using System.Collections;
 using System;
 using System.Runtime.Serialization.Formatters.Binary;
 public class LoadGame : MonoBehaviour
 {
     public Turn turn;
 
     
     public void Save()
     {
         BinaryFormatter bf = new BinaryFormatter();
         FileStream file = File.Create(Application.persidentDataPath + "/playerInfo.dat");
 
         PlayerData data = new PlayerData();
         turn.Cash = Cash;
 
         bf.Serialize(file, data);
         file.Close();
     }
     public void Load() 
     {
         if (File.Exists(Application.persidentDataPath + "/playerInfo.dat")) 
         {
             BinaryFormatter bf = new BinaryFormatter();
             FileStream file = File.Open(Application.persidentDataPath + "/playerInfo.dat", FileMode.Open);
             file.Close();
 
             Cash = turn.Cash;
         }
     }
 }
 
 [serializable]
 class PlayerData 
 {
     public int Cash;
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gjf · Jun 22, 2016 at 05:23 PM 0
Share

isn't it Serializable?

also, it looks like the closing brace on line 9 shouldn't be there...

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Dave-Carlile · Jun 22, 2016 at 08:33 PM

Most computer languages are case sensitive, meaning serializable and Serializable aren't the same thing. The attribute in this case is Serializable.

Comment
Add comment · Show 12 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bvv7070 · Jun 23, 2016 at 05:47 AM 0
Share

Now I have this error Assets/Scripts/LoadGame.cs(27,17): error CS0246: The type or namespace name `FileStream' could not be found. Are you missing a using directive or an assembly reference?

avatar image Madrize Bvv7070 · Jun 23, 2016 at 07:08 AM 0
Share

FileStream should be a part of System.IO, did you try importing it ?

avatar image Bvv7070 Madrize · Jun 23, 2016 at 12:10 PM 0
Share

After that i have this errors: Assets/Scripts/LoadGame.cs(28,59): error CS0117: UnityEngine.Application' does not contain a definition for persidentDataPath' Assets/Scripts/LoadGame.cs(28,40): error CS1502: The best overloaded method match for System.IO.File.Create(string)' has some invalid arguments Assets/Scripts/LoadGame.cs(28,40): error CS1503: Argument #1' cannot convert object' expression to type string' Assets/Scripts/LoadGame.cs(31,29): error CS0103: The name Cash' does not exist in the current context Assets/Scripts/LoadGame.cs(38,45): error CS0117: UnityEngine.Application' does not contain a definition for persidentDataPath' Assets/Scripts/LoadGame.cs(38,26): error CS1502: The best overloaded method match for System.IO.File.Exists(string)' has some invalid arguments Assets/Scripts/LoadGame.cs(38,26): error CS1503: Argument #1' cannot convert object' expression to type string' Assets/Scripts/LoadGame.cs(41,65): error CS0117: UnityEngine.Application' does not contain a definition for persidentDataPath' Assets/Scripts/LoadGame.cs(41,48): error CS1502: The best overloaded method match for System.IO.File.Open(string, System.IO.File$$anonymous$$ode)' has some invalid arguments Assets/Scripts/LoadGame.cs(41,48): error CS1503: Argument #1' cannot convert object' expression to type string' Assets/Scripts/LoadGame.cs(44,25): error CS0103: The name Cash' does not exist in the current context

Show more comments
avatar image Morgenstern_1 Bvv7070 · Jun 23, 2016 at 09:29 AM 0
Share

Add "using System.IO;"

avatar image Dave-Carlile Bvv7070 · Jun 24, 2016 at 05:39 PM 0
Share

What is your build target? File IO functionality isn't available for the web.

Once that is resolved, you really need to find some C# tutorials to learn the basics. Learning to resolve compiler errors through forum questions isn't the best use of anyone's time.

avatar image Bvv7070 · Jun 23, 2016 at 10:39 AM 0
Share

when i'm using system.IO; many errors appear.

avatar image Morgenstern_1 Bvv7070 · Jun 23, 2016 at 10:43 AM 0
Share

If you don't tell me what the errors are I can't help any further. You need to watch your capitalisation too: it's "System.IO" not "system.IO"

avatar image Bvv7070 Morgenstern_1 · Jun 24, 2016 at 05:00 AM 0
Share

Assets/Scripts/LoadGame.cs(12,59): error CS0117: UnityEngine.Application' does not contain a definition for persidentDataPath' Assets/Scripts/LoadGame.cs(12,40): error CS1502: The best overloaded method match for System.IO.File.Create(string)' has some invalid arguments Assets/Scripts/LoadGame.cs(12,40): error CS1503: Argument #1' cannot convert object' expression to type string' Assets/Scripts/LoadGame.cs(15,29): error CS0103: The name Cash' does not exist in the current context Assets/Scripts/LoadGame.cs(15,17): error CS0103: The name tura' does not exist in the current context Assets/Scripts/LoadGame.cs(22,45): error CS0117: UnityEngine.Application' does not contain a definition for persidentDataPath' Assets/Scripts/LoadGame.cs(22,26): error CS1502: The best overloaded method match for System.IO.File.Exists(string)' has some invalid arguments Assets/Scripts/LoadGame.cs(22,26): error CS1503: Argument #1' cannot convert object' expression to type string' Assets/Scripts/LoadGame.cs(25,65): error CS0117: UnityEngine.Application' does not contain a definition for persidentDataPath' Assets/Scripts/LoadGame.cs(25,48): error CS1502: The best overloaded method match for System.IO.File.Open(string, System.IO.File$$anonymous$$ode)' has some invalid arguments Assets/Scripts/LoadGame.cs(25,48): error CS1503: Argument #1' cannot convert object' expression to type string' Assets/Scripts/LoadGame.cs(28,32): error CS0103: The name tura' does not exist in the current context Assets/Scripts/LoadGame.cs(28,25): error CS0103: The name Cash' does not exist in the current context

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to Destroy game object horizontally and vertically , when hit by a Raycast 0 Answers

Always wondered how to sync animations with attack effects 0 Answers

Adding a Highscore to game 1 Answer

SPACE SHOOTER SHOOTING SHOTS TUTORIAL HELP (UNITY 5 C#) 3 Answers

C# Script not working as expected 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges