Skip to content

Instantly share code, notes, and snippets.

@seferciogluecce
Last active August 19, 2020 12:57
Show Gist options
  • Save seferciogluecce/26cacf73a13f6c56d7855add93e3e81b to your computer and use it in GitHub Desktop.
Save seferciogluecce/26cacf73a13f6c56d7855add93e3e81b to your computer and use it in GitHub Desktop.
Surround Spawn Tutorial In Unity @Devsplorer @ https://youtu.be/9wr81-ButnM
using System.Collections;
using UnityEngine;
public class CenterSurrounder : MonoBehaviour
{
public GameObject OriginalSurrounderObject;
public int SurrounderObjectCount;
private readonly float AppearWaitDuration = 0.3f;
private Transform SurrounderParentTransform;
void Start()
{
SurrounderParentTransform = new GameObject( gameObject.name + " Surrounder Parent").transform;
StartCoroutine(SurroundStepAnimated());
//Surround();
}
IEnumerator SurroundStepAnimated()
{
yield return new WaitForSeconds(AppearWaitDuration);
float AngleStep = 360.0f / SurrounderObjectCount;
OriginalSurrounderObject.transform.SetParent(SurrounderParentTransform);
for (int i = 1; i < SurrounderObjectCount; i++)
{
GameObject newSurrounderObject = Instantiate(OriginalSurrounderObject);
newSurrounderObject.transform.RotateAround(transform.position,Vector3.up,AngleStep * i);
newSurrounderObject.transform.SetParent(SurrounderParentTransform);
yield return new WaitForSeconds(AppearWaitDuration);
}
}
void Surround()
{
float AngleStep = 360 / SurrounderObjectCount;
OriginalSurrounderObject.transform.SetParent(SurrounderParentTransform);
for (int i = 1; i < SurrounderObjectCount; i++)
{
GameObject newSurrounderObject = Instantiate(OriginalSurrounderObject);
newSurrounderObject.transform.RotateAround(transform.position,Vector3.up,AngleStep * i);
newSurrounderObject.transform.SetParent(SurrounderParentTransform);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment