Hi everyone,
Today I programmed a little feature where if you clicked the inventory button, it would slide up if it was down, and down if it was up. I have a bit of a problem here, though.
The Y-Anchor Max has to scale with the screen.localresolution.height, but I don’t know how to do this in my code. I tried loads of variables and numbers but I just couldn’t get it right. Hopefully someone can help me out with this one!
Here is my code, by the way:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class inventorySlider : MonoBehaviour {
Animator anim;
public bool slideUp;
void Start(){
anim = GetComponent<Animator> ();
slideUp = false;
}
void OnMouseOver(){
if (Input.GetKeyDown (KeyCode.Mouse0) && slideUp == false) {
anim.SetBool ("slideBoolUp", true);
slideUp = true;
} else if (Input.GetKeyDown (KeyCode.Mouse0) && slideUp == true) {
anim.SetBool ("slideBoolDown", true);
slideUp = false;
}
}
void SetSlideUp(){
anim.SetBool ("slideBoolUp", false);
gameObject.GetComponent<RectTransform> ().anchorMax = new Vector2 (0, .73f); //This one is the problem. Idk what value the .73f should be to have it scale.
gameObject.GetComponent<RectTransform> ().anchoredPosition = new Vector2 (10, -90);
gameObject.GetComponent<RectTransform> ().SetSizeWithCurrentAnchors (RectTransform.Axis.Vertical, 240);
}
void SetSlideDown(){
anim.SetBool ("slideBoolDown", false);
gameObject.GetComponent<RectTransform> ().anchorMax = new Vector2 (0, 0);
gameObject.GetComponent<RectTransform> ().anchoredPosition = new Vector2 (10, -100 * Screen.height);
gameObject.GetComponent<RectTransform> ().SetSizeWithCurrentAnchors (RectTransform.Axis.Vertical, 240);
}
}
If more information is required, I will gladly provide it.
Thanks already, even if all you did was read!