我有一个下拉菜单,这个下拉列表给出了我可以通过滑块移动的游戏对象列表。基本上我要做的就是让x,y,z滑块在每个轴上移动游戏对象。我现在的问题是PlayerPrefs。我想要的一切都像魅力一样,但问题是,当我移动游戏对象并退出应用程序时,它并没有保存。下拉列表用于选择要移动的游戏对象。任何人都可以帮我吗?
这是附加到Slider的脚本。
public enum Axis{
x,y,z
};
public enum Options{
position,scale,fov,particlesystem, ui
};
public Axis axis;
public Options options;
public TMP_InputField inputField;
public TMP_InputField maxSliderInputField;
public Slider slider;
public GameObject gameObject;
public Text text;
Vector3 pos;
Vector3 tempPos;
public string playerPrefsFloatId;
public string playerPrefsStringId;
public string maxValueId;
public GameObject[] iconstoMove; // my Objects that i can choose from dropdown
public TMP_Dropdown dropDown;
if (PlayerPrefs.HasKey(playerPrefsFloatId))
{
slider.value = PlayerPrefs.GetFloat(playerPrefsFloatId);
text.text = PlayerPrefs.GetString(playerPrefsStringId);
SliderOptions();
GetAxis();
Debug.Log ("Have Key" + playerPrefsFloatId);
}
void SaveUISettings()
{
PlayerPrefs.SetFloat(playerPrefsFloatId, slider.value);
PlayerPrefs.SetFloat(maxValueId, slider.maxValue);
PlayerPrefs.SetString(playerPrefsStringId, text.text);
PlayerPrefs.Save();
}
// i use this to move object depending on axis.
void UiMovement()
{
switch (axis)
{
case Axis.x:
pos = OnValueDropDownChanged().transform.position;//gameObject.transform.position;
pos.x = slider.value;
OnValueDropDownChanged().transform.position = pos;
Debug.Log ("HI");
// gameObject = OnValueDropDownChanged();
// gameObject.transform.position = pos;
PlayerPrefs.Save();
break;
case Axis.y:
pos = OnValueDropDownChanged().transform.position;
pos.y = slider.value;
//gameObject = OnValueDropDownChanged();
OnValueDropDownChanged().transform.position = pos;
PlayerPrefs.Save();
break;
case Axis.z:
pos = OnValueDropDownChanged().transform.position;
pos.z = slider.value;
//gameObject = OnValueDropDownChanged();
OnValueDropDownChanged().transform.position = pos;
PlayerPrefs.Save();
break;
default:
Debug.LogWarning("Please Choose Axis!");
break;
}
}
// This is how i choose my gameobject from the dropdown
private GameObject OnValueDropDownChanged()
{
if (dropDown.value == 0)
{
Debug.Log ("Im Index Number " + "I'm 0");
// TODO: Movement for 0 Index
// Debug.Log (iconstoMove[0].name + " This is the name " + iconstoMove[0].transform.position + "Transform of the object");
return iconstoMove[0];
}
else if (dropDown.value == 1)
{
Debug.Log ("Im Index Number " + "I'm 1");
return iconstoMove[1];
}
else if (dropDown.value == 2)
{
Debug.Log ("Im Index Number " + "I'm 2");
return iconstoMove[2];
}
else if (dropDown.value == 3)
{
Debug.Log ("Im Index Number " + "I'm 3");
return iconstoMove[3];
}
else if (dropDown.value == 4)
{
Debug.Log ("Im Index Number " + "I'm 4");
return iconstoMove[4];
}
else if (dropDown.value == 5)
{
Debug.Log ("Im Index Number " + "I'm 5");
return iconstoMove[5];
}
else if (dropDown.value == 6)
{
Debug.Log ("Im Index Number " + "I'm 6");
return iconstoMove[6];
}
else if (dropDown.value == 7)
{
Debug.Log ("Im Index Number " + "I'm 7");
return iconstoMove[7];
}
return null;
}
现在我还有许多其他游戏对象的滑块,它们不会使用下拉列表。他们都按我的意愿工作。我唯一的问题是,当我从下拉列表中选择对象时,它永远不会保存,究竟发生了什么?