Hi everyone, I wanted to know if how can I randomly distribute the vector2 of an array on different positions… I have a code created and yet im puzzled on how to randomize the vector2 fireCoinVector… ? Thanks for the response…
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class FireCoinScript : MonoBehaviour
{
public GameObject[] fireCoins;
public GameObject otherGameObject;
public GameObject selectedGameObject;
private float randNumber;
private GameObject[,] a = new GameObject[4,4];
private TheChosenOne theChosen;
private SelectedCoins selectC;
public GUIText breakpointsText;
public Vector2[] fireCoinVector;
void Awake()
{
theChosen = otherGameObject.GetComponent<TheChosenOne> ();
selectC = selectedGameObject.GetComponent<SelectedCoins> ();
TotalSum.totalValue = 0 ;
SelectedCoins.breakPointsCount = 0;
}
void Start ()
{
for (int x=0;x<1; x++)
{
for(int y=0;y<1; y++)
{
if(!((x>0 && x<1) && (y>0 && y<1)))
{
randNumber = Mathf.RoundToInt(Random.Range(0.0f,8.0f));
int i = (int)randNumber;
GameObject randPreFab = fireCoins*;*
fireCoins = Instantiate(randPreFab) as GameObject;
fireCoins*.transform.position = new Vector2(0,0);*
_ fireCoins*.transform.parent = gameObject.transform;
a[x,y] = fireCoins;
fireCoins.SetActive(true);*_
* if((x == 0 && y == 0))*
* {*
* a[x,y].transform.position = new Vector2(-2.2f,2.816843f);*
* }*
* else if((x == 0 && y == 1))*
* {*
* a[x,y].transform.position = new Vector2(-0.6715746f,2.816843f);*
* }*
* else if((x == 0 && y == 2))*
* {*
* a[x,y].transform.position = new Vector2(0.7195799f,2.816843f);*
* //Debug.Log(i+1);*
* }*
* else if((x == 0 && y == 3))*
* {*
* a[x,y].transform.position = new Vector2(2.052296f,2.816843f);*
* //Debug.Log(i+1);*
* }*
* else if((x == 1 && y == 0))*
* {*
* a[x,y].transform.position = new Vector2(-1.996453f,1.363395f);*
* //Debug.Log(i+1);*
* }*
* else if((x == 1 && y == 3))*
* {*
* a[x,y].transform.position = new Vector2(2.052296f,1.363395f);*
* //Debug.Log(i+1);*
* }*
* else if((x == 2 && y == 0))*
* {*
* a[x,y].transform.position = new Vector2(-1.996453f,-0.07826781f);*
* //Debug.Log(i+1);*
* }*
* else if((x == 2 && y == 3))*
* {*
* a[x,y].transform.position = new Vector2(2.052296f,-0.07826781f);*
* //Debug.Log(i+1);*
* }*
* else if((x == 3 && y == 0))*
* {*
* a[x,y].transform.position = new Vector2(-1.996453f,-1.528115f);*
* //Debug.Log(i+1);*
* }*
* else if((x == 3 && y == 1))*
* {*
* a[x,y].transform.position = new Vector2(-0.6715746f,-1.528115f);*
* //Debug.Log(i+1);*
* }*
* else if((x == 3 && y == 2))*
* {*
* a[x,y].transform.position = new Vector2(0.7195799f,-1.528115f);*
* //Debug.Log(i+1);*
* }*
* else if((x == 3 && y == 3))*
* {*
* a[x,y].transform.position = new Vector2(2.052296f,-1.528115f);*
* //Debug.Log(i+1);*
* }*
* }*
* }*
* }*
* ShowGC ();*
* //turnOffSelect ();*
* }//End of Start*
* void Update()*
* {*
* NumberOfSelectedCoins ();*
* }*
* void ShowGC()*
* {*
* for(int c=0; c<theChosen.chooseCoin.Count;c++)*
* {*
* GameObject jas = theChosen.chooseCoin*
```c
*;
theChosen.chooseCoin[c] = Instantiate(jas) as GameObject;
theChosen.chooseCoin[c].transform.position = new Vector2(0,0);
theChosen.chooseCoin[c].transform.parent = gameObject.transform;
theChosen.chooseCoin[c].SetActive(true);
if(c==0)
{
theChosen.chooseCoin[c].transform.position = new Vector2(-0.6715746f,1.363395f);
}
else if(c==1)
{
theChosen.chooseCoin[c].transform.position = new Vector2(0.7195799f,1.363395f);
}
else if(c==2)
{
theChosen.chooseCoin[c].transform.position = new Vector2(-0.6715746f,-0.07826781f);
}
else if(c==3)
{
theChosen.chooseCoin[c].transform.position = new Vector2(0.7195799f,-0.07826781f);
}
}
}
void NumberOfSelectedCoins()
{
Debug.Log (BlueCoinScript.b);
if(SelectedCoins.cntCoins%BlueCoinScript.b == 0)
{
for (int n=0;n<selectC.selectedNumCoins.Count; n++)
{
Destroy(selectC.selectedNumCoins[n]);
TotalSum.totalValue = 0;
SelectedCoins.breakPointsCount++;
}
breakpointsText.text = SelectedCoins.breakPointsCount.ToString ();
selectC.selectedNumCoins.Clear();
}
}
}//End script*</em></em></em></em></em>
```