SetFloat(string, float)
Sets the float value of the preference identified by key.
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor
public static void SetFloat(string key, float value)
Parameters
Examples
// Simple script that allows a float value to be editted// in a slider. The final value is written into the Editor Preferences.using UnityEngine;using UnityEditor;using System;public class SetFloatExample : EditorWindow{ static float floatValue = 0.0f; [MenuItem("Examples/Preferences SetFloat Example")] static void Init() { Rect r = new Rect(10, 10, 200, 100); SetFloatExample window = (SetFloatExample)EditorWindow.GetWindowWithRect(typeof(SetFloatExample), r); window.Show(); } void Awake() { floatValue = EditorPrefs.GetFloat("FloatExample", floatValue); } void OnGUI() { floatValue = EditorGUILayout.Slider(floatValue, -1.0f, 1.0f); if (GUILayout.Button("Save float " + Convert.ToString(floatValue) + "?")) { EditorPrefs.SetFloat("FloatExample", floatValue); } if (GUILayout.Button("Close")) this.Close(); }}