Game Development Reference
In-Depth Information
Listing 8.4 Prepopulating Email Data in a Unity Application
Before Sending
private var toEmail = "test@email.com";
private var nameField = "My Name";
private var messageField = "Message";
function OnGUI()
{
GUI.Label(Rect(10,10,50,50),"To");
toEmail = GUI.TextField (Rect (100, 10, 200, 50), toEmail);
GUI.Label(Rect(10,60,50,50),"Name");
nameField = GUI.TextField (Rect (100, 60, 200, 50),
nameField);
GUI.Label(Rect(10,120,120,50),"Message");
messageField = GUI.TextArea(Rect(100, 120, 200, 200),
messageField);
if(GUI.Button(Rect(50,350,180,50),"Send"))
{
Application.OpenURL("mailto:" + toEmail + "?" +
"subject=Test Email&" +
"body=From: " +
nameField + "\n" + messageField);
}
}
Step 6. Play. An email form will be created in the Unity app as shown
in Figure 8.6 . When send is pressed the information entered will be
sent to the user's email client.
Note
The format for a mailto string should be mailto:email_address?email
_information . The question mark always separates the email address of
the recipient with extra data, which are divided into a number of headers
separated by ampersands. Each header has a name and its own value set
with an equals sign. The headers can include:
subject—the text that will appear in the subject line
body—the email message
cc—the email address of others to send a copy of the message
bcc—the email address of others who will receive the email but
not appear in the send email message of the original
Search Nedrilad ::




Custom Search