x


Creating a Space to Type a Name

I am trying to create a space where player's can enter a name for their hero when they start a new game. Here is my code:

using UnityEngine; using System.Collections;

public class Namespace : MonoBehaviour { public string hero;

// Use this for initialization
void Start () {
    hero = new string();
}

// Update is called once per frame
void Update () {

}

void OnGUI () {
    GUI.Label(new Rect(10,10,50,25), "Enter Your Heroes Name:");
    hero = GUI.TextArea(new Rect(65,10,100,25), hero);
}

} _________________________________________________________________________________________

I get an error that says

Assets/Scripts (Medina)/Namespace.cs(9,36): error CS1729: The type string' does not contain a constructor that takes0' arguments

Any help is greatly appreciated :-)

more ▼

asked Apr 16 '12 at 03:49 PM

latsushi gravatar image

latsushi
43 9 19 24

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Just remove that line, you don't need it. You could set hero = "" if you want.

more ▼

answered Apr 16 '12 at 04:08 PM

DaveA gravatar image

DaveA
26.8k 153 171 257

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x67
x61
x6
x4

asked: Apr 16 '12 at 03:49 PM

Seen: 416 times

Last Updated: Apr 16 '12 at 04:08 PM