Hi,
I’m trying to build a mini inventory item selection box popup.

I created a C# script and attached to player object. In OnGUI() function I calculated the position and then;
GUI.DrawTexture (contentSection, contentBG);
GUILayout.BeginArea (contentSection);
scrollPos = GUILayout.BeginScrollView(scrollPos, true, false, GUILayout.Width (contentSection.width), GUILayout.Height (contentSection.height));
GUILayout.BeginHorizontal ();
for (int i = 0; i < items.Count; i++) {
GUILayout.Box (items[i].Texture);
}
GUILayout.EndHorizontal ();
GUILayout.EndScrollView ();
GUILayout.EndArea ();
And I’m handling the Input’s in Update() function;
void Update() {
if (Input.GetKeyDown (toggleKey)) {
ToggleInventory ();
}
if (Input.GetKeyDown (previousKey)) {
Debug.Log ("left item");
scrollPos.x = scrollPos.x - 50;
} else if (Input.GetKeyDown (nextKey)) {
Debug.Log ("right item");
scrollPos.x = scrollPos.x + 50;
}
}
I have some questions;
- How can I lerp or damp scrollposition? I tried Mathf.Lerp but didn’t work. (Maybe scrollpos is overridden in ongui?)
- And I want a nice opening & closing animation but I don’t know how to achieve that in OnGUI function.
And any suggestions are welcome, I’m a newbie, thanks.