Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Set(fieldName: string, val: FieldType): void;
void Set(string fieldName, FieldType val);
def Set(fieldName as string, val as FieldType) as void

Parameters

fieldNameThe name of the field (e.g. int counter; would have fieldName = "counter").
valThe value to assign to the field. It has to match the field type.

Description

Set the value of a field in an object (non-static).

The generic parameter determines the field type.

	// Create a android.text.format.Time object, and set the 'allDay' field to true.
	function Start() {
		var jo = new AndroidJavaObject("android.text.format.Time");
		jo.Set.<boolean>("allDay", true);
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Start() {
        AndroidJavaObject jo = new AndroidJavaObject("android.text.format.Time");
        jo.Set<bool>("allDay", true);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Start() as void:
		jo as AndroidJavaObject = AndroidJavaObject('android.text.format.Time')
		jo.Set[of bool]('allDay', true)