Skip to content

Instantly share code, notes, and snippets.

@gremito
Created January 4, 2020 03:32
Show Gist options
  • Save gremito/6b6a1a5cf081d39c22a2d3768ffac617 to your computer and use it in GitHub Desktop.
Save gremito/6b6a1a5cf081d39c22a2d3768ffac617 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoinGame : MonoBehaviour
{
[SerializeField]
private GameObject coin;
private const int MAX_COIN = 10;
// Start is called before the firsst frame update
void Start()
{
System.Random random = new System.Random();
// Create Coin
for(int i = 0; i < MAX_COIN; i++)
{
var go = Instantiate(
coin,
new Vector3(
transform.position.x,
transform.position.y+3,
transform.position.z
),
transform.rotation
);
// random
int positionX = random.Next(-50, 50);
int positionZ = random.Next(-50, 50);
go.GetComponent<Transform>().position = new Vector3(
positionX,
go.GetComponent<Transform>().position.y,
positionZ
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment