Skip to content

Instantly share code, notes, and snippets.

@PrashantUnity
Last active August 21, 2022 10:44
Show Gist options
  • Save PrashantUnity/f26f94187e1117804b382895822a7880 to your computer and use it in GitHub Desktop.
Save PrashantUnity/f26f94187e1117804b382895822a7880 to your computer and use it in GitHub Desktop.
Generate Prefab on Spherical Object
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MapGenerator : MonoBehaviour
{
public GameObject objectToGenerated;
public float theta;
public float radius;
public float numberOfObject = 24;
private void Start()
{
GenerateMap();
}
public void GenerateMap()
{
for (int i = 1; i < numberOfObject; i++)
{
for (int j = 0; j < numberOfObject; j++)
{
var x = radius *Mathf.Sin(theta*j)*Mathf.Cos(theta*i);
var y = radius * Mathf.Cos(theta * j);
var z = radius *Mathf.Sin(theta*j)*Mathf.Sin(theta * i);
var pos = new Vector3(x, y, z);
Instantiate(objectToGenerated, pos, Quaternion.identity, transform);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment