• 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 /
avatar image
0
Question by Lodos3 · May 20, 2012 at 10:18 PM · prefabscustom

Editable Text Forms in Prefabs [C#]

I'm not sure if my Title makes sense, so i will try and explain what it is i want. I did try and search for parts of my idea but nothing exact, so please if anyone can point me in the right direction i would be most grateful :

I have a set of prefabs (52) and i wish to attached editable text forms to them. In the Game scene (where the prefabs are randomly picked out) i want the text form to pop up underneth the prefab called. In the Rules scene i have built, i want the user to be able to edit text forms (before playing) , allowing them to set custom rules.

I hope i've made this clear.

Comment
Add comment · Show 5
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 Lodos3 · May 21, 2012 at 11:55 AM 0
Share

How would i go by adding 52 text forms using this code?

      strUsername = GUILayout.TextField(strUsername, 20, GUILayout.Width(100));

i want this to be editable VIA a different scene

avatar image Lodos3 · May 22, 2012 at 12:58 PM 0
Share

Could anyone enlighten me ?

avatar image whydoidoit · May 22, 2012 at 01:08 PM 0
Share

That is a big old subject!

You would need to write OnGUI code or use something like NGUI to build your editable forms.

You would need to handle selecting items - so knowing that they've been clicked on and then in the gui code you would work out the screen location from the world location of the object clicked and then try to position it underneath.

If you can cope with the GUI just appearing at one location on the screen then it would be easier.

Attach colliders to your prefabs, add a script which gets an On$$anonymous$$ouseDown to know that it has been selected - update some variable with currently selected object and use that variable in an OnGUI to know which fields to fill in on your text form.

This is not an easy thing to do, it's not that hard, but it is that tricky. Feels to me like working around on understanding GUI, choosing which way of producing GUI (NGUI, EZGUI, OnGUI in Unity), learning that component first etc would be the way to go.

avatar image Lodos3 · May 22, 2012 at 02:05 PM 0
Share

Right i've sorted figured out how i can do it .. but i dont know what would be best to do ....

On my prefabs i need to add a "Read" .txt file, i was thinking about adding a script to all my prefabs but define which line to read from in the text file. So the text file will contain a line for each prefab...

In a different scene , i want to be able to save text for each prefab (each line in the text file).

I saw something that may help , but i dont know how to get it working with unity (maybe use resources folder?)

Writing to a Text File Listing 1: Writing Text Data to a File: TextFileWriter.cs

using System;

using System.IO;

namespace csharp_station.howto

{

    class TextFileWriter

    {

        static void $$anonymous$$ain(string[] args)

        {

           // create a writer and open the file

            TextWriter tw = new StreamWriter("date.txt");



            // write a line of text to the file

            tw.WriteLine(DateTime.Now);



            // close the stream

            tw.Close();

        }

    }

}

Reading From a Text File

Listing 2 shows how to read from a text file: Listing 2: Reading Text Data from a File: TextFileReader.cs

using System;

using System.IO;

namespace csharp_station.howto

{

    class TextFileReader

    {

        static void $$anonymous$$ain(string[] args)

        {

            // create reader & open file

            Textreader tr = new StreamReader("date.txt");


            // read a line of text

            Console.WriteLine(tr.ReadLine());


           // close the stream

            tr.Close();

        }

    }

}

avatar image Lodos3 · May 22, 2012 at 02:26 PM 0
Share

would something like this help ?

http://msdn.microsoft.com/en-us/library/aa287548%28v=vs.71%29.aspx

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

What prefab is my game object an instance of? 1 Answer

No "Standard Assets" in Project tab, new to unity, please help 2 Answers

Deleting instantiated prefabs clones? 2 Answers

Instantiating Multiple Prefabs at Runtime 0 Answers

Increasing Prefabs lowers FPS (frame rate) 1 Answer


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