Struct 如何将flout var(触摸屏y pos)转换为矢量2?
我想在android中用触摸屏滚动我的滑块,我有以下代码:Struct 如何将flout var(触摸屏y pos)转换为矢量2?,struct,Struct,我想在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, " "); } fun
// 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();
//用于滚动
变量滚动位置:Vector2=Vector2.0;
//标签样式
var touch=Input.touch[0];
函数OnGUI(){
windowMain=GUI.Window(1,Rect(0,0,Screen.width,Screen.height),WindowFunctionMain,“”;
}
函数WindowFunctionMain(窗口ID:int){
scrollPosition=GUI.BeginScrollView(Rect(0,Screen.height/2,Screen.width,Screen.height/4+20),scrollPosition,Rect(0,0,650,0));
如果(touch.phase==TouchPhase.Moved)
scrollPosition=scrollPosition+touch.deltaPosition.y;
对于(var i=0;i
但是在这一行中有错误:scrollPosition=scrollPosition+touch.deltaPosition.y
运算符“+”不能与类型为“UnityEngine.Vector2”的左侧和类型为“float”的右侧一起使用。
我怎样才能解决这个问题?
TNX.将浮点添加到Vector2没有任何意义。Vector2如何知道要将浮点添加到其哪些组件
scrollPosition.y += touch.deltaPosition.y;
或
你的题目与问题无关。
scrollPosition += new Vector2(0, touch.deltaPosition.y);