就看xA,xB,想if運行完以后用來運算,顯示“在使用未賦值的區域變數”,無法運算。如果開始定義時給賦初始值xA=xB=0,最后結果xStep就只會等于0,經驗算兩個if陳述句都是執行了的,但陳述句內賦的值陳述句外就沒有。
求解,感謝,目的是得到兩個if后xB-xA的結果。
Vector2 touchPosition = Input.mousePosition;
bool isStillOn = false;
float xA, yA, tA, xB, yB, tB;
if (Input.GetMouseButtonDown(0) && isStillOn == false)
{
xA = touchPosition.x;
yA = touchPosition.y;
tA = Time.deltaTime;
isStillOn = true;
Debug.Log(tA); Debug.Log(yA); Debug.Log(xA);
}
if(Input.GetMouseButtonUp(0))
{
xB = touchPosition.x;
yB = touchPosition.y;
tB = Time.deltaTime;
isStillOn = false;
Debug.Log(tB); Debug.Log(yB); Debug.Log(xB);
}
float xStep = (xB - xA) / 10;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/226541.html
標籤:新手樂園
上一篇:字符替換
下一篇:字符替換
