所以我在一個統一的 c# 腳本中創建了這個方法,但是它給出了錯誤'區域變數'verticalMovementSpeed'可能在訪問之前沒有被初始化'
代碼:
float VerticalAirMovementSpeed(bool IsGrounded, float verticalMovementInput)
{
//Makes forward and backward sensitivity (vertical sensitivity) controllable separately form eachother
float verticalMovementSpeed;
//forward and backward movement speed in air and on the ground
if (verticalMovementInput < 0 && !IsGrounded)
{
verticalMovementSpeed = backwardAirMovementSpeed;
}
else if (verticalMovementInput > 0 && !IsGrounded)
{
verticalMovementSpeed = forwardAirMovementSpeed;
}
else if (verticalMovementInput > 0 && IsGrounded)
{
verticalMovementSpeed = forwardMovementSpeed;
}
else if (verticalMovementInput < 0 && IsGrounded)
{
verticalMovementSpeed = backwardMovementSpeed;
}
return verticalMovementSpeed * verticalMovementInput;
}
(C#)
uj5u.com熱心網友回復:
你可以從以下開始:
float verticalMovementSpeed = float.Parse("0.00");
這樣它就會被初始化。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/467349.html