-2

我想在android中用触摸屏滚动我的滑块,我有这个代码:

// for scroll
var scrollPosition : Vector2 = Vector2.zero;
//label style
var touch = Input.touches[0];
function OnGUI() {
windowMain = GUI.Window(1, Rect(0,0,Screen.width,Screen.height), WindowFunctionMain, " ");  
}
function WindowFunctionMain (windowID : int) {

scrollPosition = GUI.BeginScrollView(Rect (0,Screen.height/2,Screen.width,Screen.height/4+20),scrollPosition, Rect (0, 0, 650, 0)); 

if(touch.phase == TouchPhase.Moved)
    scrollPosition = scrollPosition +  touch.deltaPosition.y;

for (var i=0;i < ImgSliderProducts.Length;i++)
{
    GUI.DrawTexture(Rect(20+(i* 100),10,100,100), ImgSliderProducts[i],ScaleMode.ScaleToFit,true);
}

GUI.EndScrollView(); 

但在这一行有错误:scrollPosition = scrollPosition + touch.deltaPosition.y;

运算符“+”不能与“UnityEngine.Vector2”类型的左侧和“float”类型的右侧一起使用。我怎么解决这个问题 ?TNX。

4

1 回答 1

0

向 Vector2 添加浮点数没有任何意义。Vector2 如何知道您想将浮动添加到它的哪个组件?

scrollPosition.y += touch.deltaPosition.y;

或者

scrollPosition += new Vector2(0, touch.deltaPosition.y);
于 2013-10-02T14:38:58.503 回答