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 MohamedMahrous · Oct 26, 2016 at 08:46 AM · c#unity5

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();
         }
     }
 }

Comment
Add comment · Show 8
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 hexagonius · Oct 26, 2016 at 08:53 AM 0
Share

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.

avatar image MohamedMahrous hexagonius · Oct 26, 2016 at 09:06 AM 0
Share

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 ..

avatar image doublemax MohamedMahrous · Oct 26, 2016 at 10:17 AM 0
Share

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.

Show more comments
Show more comments
avatar image MohamedMahrous · Oct 26, 2016 at 10:35 AM 0
Share

@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 ?

avatar image doublemax MohamedMahrous · Oct 26, 2016 at 10:57 AM 0
Share

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.

avatar image MohamedMahrous doublemax · Oct 28, 2016 at 08:16 AM 0
Share

Thanks @doublemax . That work just fine and I got what you mean by the difference between console and GUI application.

Thanks alot

0 Replies

· Add your reply
  • Sort: 

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

250 People are following this question.

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

Related Questions

I guys I have a really hard question 0 Answers

Is there a way to make a script activate when you look at an object? 1 Answer

Move a separate object forward on collision between particle system and another object 0 Answers

Is there possibility to have 1 Script for Different SceneSwitches? 2 Answers

Increase Score When Moving Up (Script Help) 0 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