- Home /
File does not have a definition for Create error
 using UnityEngine;
 using System.Collections;
 using System;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.IO;
 
 public static GameControl s_control;
 
     void Awake()
     {
         //Is there is no current GameControl, make this te current GameControl
         if (s_control == null)
         {
             DontDestroyOnLoad(gameObject);
             s_control = this;
         }
         else if(s_control != this)
         {
             Destroy(gameObject);
         }
 
         
         if (GameObject.FindGameObjectWithTag("Player"))
         {
             s_Survival = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerGUISurvival>();
             //s_Player = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
             s_Inventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
         }
         
     }
 
     public void Save()
     {
         //This will create the file
         BinaryFormatter bf = new BinaryFormatter();
         //Attempt to open a file                               //FILE NAME OF SAVES
         FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat");
         
         PlayerData data = new PlayerData();
 
         //Stuff
 
         //We save into the binary formatter, the file and in the file, our data.
         bf.Serialize(file, data);
         file.Close();
     }
 
     public void Load()
     {
         if (File.Exists(Application.persistentDataPath + "/playerInfo.dat"))
         {
             BinaryFormatter bf = new BinaryFormatter();
             FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open);
 
             //Container to pull data out
             PlayerData data = (PlayerData)bf.Deserialize(file);
             file.Close();
            
 
             //Stuff
         }
     }
So this is the code I have, it worked PERFECTLY before, but when I created another script, this error started to appear: " 'File' does not contain a definition for 'Create' " So I don't know what Im doing wrong... My unity is Set to PC, LINUX & MAC so it isn't the problem and its starting to drive me crazy :p Im using latest unity version and Visual Studio
Answer by Eric5h5 · Oct 04, 2015 at 02:18 PM
You have your own class called File, which doesn't have a Create method. Either rename your class or disambiguate the Create call.
Omg I just pacepalmed myself, the script I created is named File.... Thanks!
Your answer
 
 
             Follow this Question
Related Questions
File saving error 1 Answer
FileMode.Create an encoded xml file in UTF-8 1 Answer
Serialize XML File Delete and CreateNew 2 Answers
Can't use .Add-Function for List 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                