2017-01-03 58 views
-1
  • 我有一個10級的旋轉輪。如何提高紡車轉速時的轉速一致

  • 旋轉從按鈕單擊的隨機位置開始。我不想在第10師停止旋轉輪。

    void Start() 
    { 
    Panel = GameObject.FindGameObjectWithTag("Panel1"); 
    Panel.SetActive (false); 
    
    maxAngle = Random.Range (1440.0f, 3600.0f); 
    //print("maxAngle"+maxAngle); 
    spinning = false; 
    anglePerItem = 360/prize.Count; 
    myStartAngle = (maxAngle % 360)*2; 
    //print("myStartAngle"+myStartAngle); 
    transform.eulerAngles = new Vector3 (0.0f, 0.0f, myStartAngle); 
    
    } 
    
    
    
    public void Onclick() 
    { 
    
    if (!spinning) { 
    
        randomTime = Random.Range (20, 25); 
        itemNumber = Random.Range (1, prize.Count); 
        //float maxAngle = 360 * randomTime + (itemNumber * anglePerItem); 
    // float maxAngle = 360; 
        StartCoroutine (SpinTheWheel (1 * randomTime, maxAngle)); 
    } 
    } 
    
    
    IEnumerator SpinTheWheel (float time, float maxAngle) 
    { 
    spinning = true; 
    
    SpinsEligibleFrSpinner = PlayerPrefs.GetInt ("SpinsEligibleFrSpinner"); 
    SpinsEligibleFrSpinner = SpinsEligibleFrSpinner - 1; 
    PlayerPrefs.SetInt ("SpinsEligibleFrSpinner",SpinsEligibleFrSpinner); 
    
    float timer = 0.0f;   
    
    float startAngle =myStartAngle; 
    
    
    int animationCurveNumber = 0; 
    
    int i=0; 
    while (timer < time) { 
        //to calculate rotation 
    
        timer += Time.deltaTime; 
        angle = maxAngle * animationCurves [animationCurveNumber].Evaluate (timer/time) ; 
        if(i==0) 
        { 
         //print ("angle---"+angle); 
        } 
        i = i + 1; 
    
        transform.eulerAngles = new Vector3 (0.0f, 0.0f, angle); 
    
    
    
        yield return 0; 
    } 
    
    
    spinning = false; 
    
    
    } 
    

我怎麼能做到這一點,因爲使用隨機是我沒有得到任何想法

  • 是有可能增加的速度,如果旋轉車輪轉動如果在要 結束第十師。

回答

1

你可以使用Random初始化initial speed和你的車輪deceleration。然後,您的Update()方法只是在給定車輪轉速值的情況下旋轉車輪。

float _speed; //in m/s 
float _deceleration; //in m/s^2 
bool _spin; 

void Update() 
{ 
    if (_spin) 
    { 
     transform.Rotate(_speed * Vector3.up * Time.deltaTime, Space.Self); 
     _speed -= _deceleration * Time.deltaTime; 

     //Stop when too slow. 
     if (_speed < minSpeed) 
     { 
     if (//wheel is at 10th position) 
      _speed += minSpeed; //Push it a little more. You can use random here too. 
     else 
      _spin = false; 
     } 

    } 
} 

void OnClick() 
{ 
    if (!_spin) 
    { 
     _spin = true; 
     _speed = Random.Range(speedFloor, speedCeiling); 
     _deceleration = Random.Range(decFloor, decCeiling); 
    } 
} 
+0

soo它永遠不會在第10師結束? @Lincoln –

+0

是的,編輯。沒有意識到你不想讓它停在第10師。 – Lincoln