2016-07-30 41 views
0
using System; 
using UnityEngine; 
using System.Collections; 
using UnityStandardAssets.Characters.ThirdPerson; 

public class Multiple_objects : MonoBehaviour { 

    public GameObject prefab; 
    public GameObject[] gos; 
    public int NumberOfObjects; 
    private ThirdPersonCharacter[] thirdPersonCharacter; 
    private Animator[] _animator; 
    private int count = 0; 

    void Awake() 
    { 
     Vector3 v3 = prefab.transform.position; 
     _animator = new Animator[NumberOfObjects]; 
      gos = new GameObject[NumberOfObjects]; 
     for(int i = 0; i < gos.Length; i++) 
     { 
      count = count + 2; 
      GameObject clone = (GameObject)Instantiate(prefab, Vector3.zero, Quaternion.identity); 
      gos [i] = clone; 
      gos [i].transform.position = new Vector3 (v3.x - count, v3.y, v3.z); 
      _animator [i] = gos[i].GetComponent<Animator>(); 
      Math.Round(Random 

當我鍵入點隨機後像:隨機。 我只有平等相待,的ReferenceEquals爲什麼屬性範圍不存在於統一的隨機類中?

如果我例如創建隨機的變量:

Random _random; 

然後我鍵入_random。 我得到更多propeties但不Range。

+0

我[RandomGenerator(https://github.com/chanibal/RandomGenerator)實用程序只是一個無恥的插件,它可以解決你的問題具有可實例化的「隨機」類,並且更好地控制值的隨機性。 –

回答

1

您同時使用UnityEngine和系統命名空間。這兩個命名空間都包含一個隨機類,因此Visual Studio/Unity不知道要使用哪一個。要指定要使用的是隨機的,您只需將做到這一點:

UnityEngine.Random.Range(0.0f, 5.0f); 
1

爲什麼屬性範圍不存在於統一的隨機類中?

隨機_random; _random.Rand ...

RangeRandomstatic功能。你不需要創建類的實例來使用靜態函數。你直接調用靜態函數。

這應做到:Random.Range(0f,3f);

如果你得到Random' is an ambiguous reference between System.Random」和UnityEngine.Random' error then that's because you have使用系統;`(你在你的代碼一樣),因此,你必須使用命名空間訪問Unity隨機函數。

UnityEngine.Random.Range(0f, 3f); 
1

寫UnityEngine.Random.Range

要弄清的命名空間。

除非你想在.NET隨機的(在這種情況下看對方的回答)

相關問題