Created
June 23, 2020 19:28
-
-
Save smkplus/1f3f6b46a0a54db3353cc90bc048d6e9 to your computer and use it in GitHub Desktop.
Circle.cs
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 Circle : MonoBehaviour | |
{ | |
[SerializeField] private GameObject prefab; | |
[SerializeField] private float radius = 2; | |
[SerializeField] private float number = 1; | |
private float t; | |
IEnumerator Start() | |
{ | |
while (t < 6.28f) | |
{ | |
t += 6.28f / number; | |
var x = Mathf.Sin(t)*radius; | |
var z = Mathf.Cos(t)*radius; | |
var spawn =Instantiate(prefab, new Vector3(x, 0, z), Quaternion.identity, transform); | |
var lookAngle = Mathf.Atan2(x, z) * Mathf.Rad2Deg; | |
spawn.transform.eulerAngles = Vector3.up * lookAngle; | |
yield return null; | |
} | |
} | |
} |
Author
smkplus
commented
Jun 23, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment