DeveloperConsole.SetField C# (CSharp) Method

SetField() public method

public SetField ( GameObject gameObject, Component component, string fieldName, string argument ) : void
gameObject GameObject
component Component
fieldName string
argument string
return void
	void SetField ( GameObject gameObject, Component component, string fieldName, string argument )
	{
		Type componentType = component.GetType();
		FieldInfo fInfo = componentType.GetField( fieldName );
		
		if ( fInfo != null )
		{
			bool paramSuccess = true;
			object pArgument = null;
			
			paramSuccess = ParseStringToObject(fInfo.FieldType, argument, ref pArgument);
			
			if (paramSuccess)
			{
				fInfo.SetValue(component, pArgument);
			}
			else
			{
				PrintToConsole( "Failed to set variable of type " + fInfo.FieldType.ToString() );
			}
		}
	}