This script for randoming multiple prefab ^ i have double this code and get 2 multiple prefab randomly at same time but here my problem :
1- the 1st is problem on my result is sometimes get 2 same value in random (How to get 2 a different random prefab at same times ^ random A-Random B , A not same value B)
2- The result Sometimes fixed in horizontal angle but sometimes 2 value image fused and sometimes in Vertical position (How to get Fixed colider image in horizontal line )
-Screen shot on Bottom-
This preview
using UnityEngine;
using System.Collections;
public class SpawnMultipleOBJ_angka : MonoBehaviour {
private Vector3 startPosition;
private float newXPos = 0f;
public float moveSpeed = 1f;
public float moveDistance = 4f;
//initiate aray
public GameObject[] gameObjectSet;
public float timeLeftUntilSpawn = 0f;
public float startTime = 0f;
public float secondsBetweenSpawn = 3f;
// Use this for initialization
void Start () {
startPosition = transform.position;
}
void SpawnRandomObject(){
int whichItem = Random.Range (0, 9);
//Debug.Log ("Our Random number is " + whichItem);
GameObject myObj = Instantiate (gameObjectSet [whichItem])as GameObject;
myObj.transform.position = transform.position;
}
// Update is called once per frame
void Update () {
//Move Distant
newXPos = Mathf.PingPong (Time.time * moveSpeed, moveDistance) - (moveDistance / 2f);
transform.position = new Vector3 (newXPos, startPosition.y, startPosition.z);
timeLeftUntilSpawn = Time.time - startTime;
if (timeLeftUntilSpawn >= secondsBetweenSpawn){
startTime = Time.time;
timeLeftUntilSpawn = 1;
SpawnRandomObject();
}
}
}