public class Cube1 : UdonSharpBehaviour
{
[SerializeField]
GameObject[] CardDeck;
void Start()
{
}
public override void Interact()
{
if(!Networking.IsOwner(Networking.LocalPlayer, this.gameObject))
{
Networking.SetOwner(Networking.LocalPlayer, this.gameObject);
foreach(GameObject card in CardDeck)
{
Networking.SetOwner(Networking.LocalPlayer, card);
}
}
int[] shuffleIndexArray = new int[CardDeck.Length];
for (int a=0; a<shuffleIndexArray.Length; a++)
{
shuffleIndexArray[a] = -1;
var cardPos = CardDeck[a].transform.localPosition;
var cardRoate = CardDeck[a].transform.localRotation;
cardPos.x = 0.0F;
cardPos.y = 0.0F;
cardPos.z = 0.0F;
cardRoate.x = 0.0F;
cardRoate.y = 0.0F;
cardRoate.z = 0.0F;
CardDeck[a].transform.localPosition = cardPos;
CardDeck[a].transform.localRotation = cardRoate;
}
for (int i=0; i<CardDeck.Length; i++)
{
bool SetIndex = false;
do
{
bool isExists = false;
int tempIndex = Random.Range(0, shuffleIndexArray.Length);
for(int j=0; j<shuffleIndexArray.Length; j++)
{
if(shuffleIndexArray[j] == tempIndex)
{
isExists = true;
break;
}
}
if(!isExists)
{
shuffleIndexArray[i] = tempIndex;
SetIndex = true;
}
}
while (!SetIndex);
}
for(int k=0; k<CardDeck.Length; k++)
{
var pos = CardDeck[k].transform.localPosition;
pos.y = 0.01F * (float)shuffleIndexArray[k];
CardDeck[k].transform.localPosition = pos;
}
}
}