UGUI實現介面隨滑鼠移動效果
void Start () {
BG = GameObject.Find("BackGround");
UIBG = BG.GetComponent<RectTransform>();
ZeroScreen = new Vector3(Screen.width / 2, Screen.height / 2, 0);
}
void Update () {
//Debug.Log("UI" + UIBG.localPosition);
//Debug.Log("Zero : "+ZeroScreen);
MousePos = Input.mousePosition ;
//Debug.Log("MousePos : " + MousePos);
Vector3 DetaMouse = MousePos - ZeroScreen;
BG.GetComponent<RectTransform>().localPosition = -1 * DetaMouse * rate;
}
原理很簡單,就是滑鼠到螢幕中心的位置,就是UGUI的位置的映象
再把Vector乘個Rate 感覺效果就出來了