- Home /
Parameters at Startup
Hey guys,
I'm having a great deal of trouble figuring out how to get parameters on an application's StartUp. I've been working on this almost all day, but nothing seems to work. I can't give Start() parameters, and I can't get Environment.GetCommandLineArgs to return any value. Maybe I'm sending the parameters wrong, but I'm getting tired of trying to figure this out. If any of you can give me a quick example, I'll be really grateful!
Thanks for your time - Gibson
Answer by Dom3D · Dec 19, 2012 at 02:12 AM
Under OSX I made the following testrun, maybe it helps you to find your issue
Terminal line:
open CMDTest.app/ --args -myarg andstuff and more
MonoBehavior
using UnityEngine;
using System.Collections;
using System;
public class Info : MonoBehaviour
{
static string cmdInfo = "";
void Start ()
{
string[] arguments = Environment.GetCommandLineArgs();
foreach(string arg in arguments)
{
cmdInfo += arg.ToString() + "\n ";
}
}
void OnGUI()
{
Rect r = new Rect(5,5, 800, 500);
GUI.Label(r, cmdInfo);
}
}
Hey, thanks for the tip! Do you have any tips on sending arguments from code?
@AVividLight: you mean running a program that calls the player? Would that be a .Net application? Or another Unity player process?
Thanks for answering so quickly, Dom3D, and sorry it's taken me so long to respond!
It's a Unity Application, and I've tried using Process.Start (with arguments), and it's doesn't seem to work. $$anonymous$$aybe I need to try again, but do you have any tips?
I just got it working, thanks so much!
If anybody is wondering, to send the arguments, you must include "--args". example: Process.Start(path , "--args myArgument");
This helped me a lot guys, thanks for this! I'm building a automation tool for building my apps for Android/iOS remotely, and needed to send in version numbers for the build process!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How can I access Animator parameters in C# 2 Answers
Black And White To Colour Game Environment? 1 Answer
Is this a valid way to add a parameter to a class? 0 Answers