error CS0117: `System.Console' does not contain a definition for `ReadKey'
Hello Guys,
Hope everything is going well with you all. I am new to unity but I used to use C#. I was trying to build a simple problem which is interacting with an XML file. When I did the code on C# and tried it already it worked just fine and I had a good result. But now when I take that code into unity and try it by my self I get an error : error CS0117: System.Console does not contain a definition for `ReadKey'
Can anyone help me in this please ?
CODE :
 using System;
 using System.Text;
 using System.Xml;
 
 namespace trying1
 {
     class App2
     {
         static void Main(string[] args)
         {
             XmlReader xmlReader = XmlReader.Create("...........");
             while (xmlReader.Read())
             {
                 if ((xmlReader.NodeType == XmlNodeType.Element) && ((xmlReader.Name == "VILLA") || (xmlReader.Name == "VILLA2") || (xmlReader.Name == "VILLA3")))
                 {
                     if (xmlReader.HasAttributes)
                         Console.WriteLine(xmlReader.GetAttribute("Name") + ": " + xmlReader.GetAttribute("add.") + "\n ");
                 }
             }
             Console.ReadKey();
         }
     }
 }
It's probably not in the .NET 2.0 Subset Unity usually uses. Try changing it to .NET 2.0 under Build Settings -> Player Settings -> Other -> API Compatibility Level.
Thank you for your help. I checked already and it is under ( .NET 2.0 Subset ) .. still having the same issue , Weird part that It is working properly in visual basic but its not working in Unity5 ..
In a Unity app waiting for a key press this way doesn't make sense. Given the update-loop architecture of Unity you need a different approach to certain tasks.
@doublemax Simply ,,
I am trying to $$anonymous$$ch myself the following :
When A user Press on a certain object like a sphere for example .. The code suppose to log into my Xml file which I already uploaded online and get the necessary data from it.
The code I posted is working perfect on standalone C# and I understood from you its totally different approach when using Unity. So What Can I use for similar function ?
The difference is the same as between a console application and a GUI application. A console application usually has a very linear program flow while the GUI application is event driven and reacts to user's actions.
Save the following code as "X$$anonymous$$LTest.cs". In Unity, drag the script into "Assets" in the project window. Then create a GameObject and drag this script onto it.
 using System.Xml;
 using UnityEngine;
 
 public class X$$anonymous$$LTest : $$anonymous$$onoBehaviour
 {
   void Update ()
   {
     if( Input.Get$$anonymous$$ey($$anonymous$$eyCode.Return) )
     {
       XmlReader xmlReader = XmlReader.Create("...........");
       while (xmlReader.Read())
       {
         if ((xmlReader.NodeType == XmlNodeType.Element) && ((xmlReader.Name == "VILLA") || (xmlReader.Name == "VILLA2") || (xmlReader.Name == "VILLA3")))
         {
           if (xmlReader.HasAttributes)
             Debug.Log(xmlReader.GetAttribute("Name") + ": " + xmlReader.GetAttribute("add.") );
         }
       }
     }    
   }
 }
When you press "Return" your code will get executed. The output will appear in the Unity console window.
Thanks @doublemax . That work just fine and I got what you mean by the difference between console and GUI application.
Thanks alot
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                