Last active
August 21, 2022 10:44
-
-
Save PrashantUnity/f26f94187e1117804b382895822a7880 to your computer and use it in GitHub Desktop.
Generate Prefab on Spherical Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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