Last active
August 19, 2020 12:57
-
-
Save seferciogluecce/26cacf73a13f6c56d7855add93e3e81b to your computer and use it in GitHub Desktop.
Surround Spawn Tutorial In Unity @Devsplorer @ https://youtu.be/9wr81-ButnM
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 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