2016-07-30 2 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 입력합니다. 나는 더 많은 산물을 얻지 만 범위는 얻지 못한다.

+0

내 [RandomGenerator] (https://github.com/chanibal/RandomGenerator) 유틸리티 그냥 뻔뻔한 플러그를, 그것의 문제를 해결 인스턴스 가능한'Random' 클래스를 가지며 값의 무작위성을보다 잘 제어 할 수 있습니다. –

답변

1

당신은 (다른 답의 경우 모양에) 그물 랜덤를 원하는하지 않는 한. 이 두 네임 스페이스 모두 랜덤 클래스를 포함하므로 Visual Studio/Unity는 어느 클래스를 사용할지 알지 못합니다. 사용할 임의 지정하려면, 당신은 단순히 이런 짓을 했을까 :

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

왜 속성 범위가 단일성으로 랜덤 클래스에 존재하지 않습니까?

랜덤 _random; _random.Rand ...

RangeRandom는 클래스의 static 함수이다. 클래스 내부에 정적 함수를 사용하기 위해 클래스의 인스턴스를 생성 할 필요가 없습니다. 정적 함수를 직접 호출합니다. `(당신은 당신의 코드에 한 함) 따라서 당신은 전체 네임 스페이스를 사용해야합니다, 당신은 시스템을 사용하여 Random' is an ambiguous reference between System.Random '와 UnityEngine.Random' error then that's because you have을 얻는 경우 Random.Range(0f,3f);

:

이 그것을해야 유니티 랜덤 기능에 액세스 할 수 있습니다.

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

는 쓰기 UnityEngine.Random.Range

당신은 네임 스페이스를 명확히해야한다.

당신은 UnityEngine 및 시스템 네임 스페이스를 모두 사용하는