Skip to content

Instantly share code, notes, and snippets.

@SamatKadyrov
Created December 5, 2023 18:04
Show Gist options
  • Save SamatKadyrov/5b7c5485841019eac4526d878c0ed969 to your computer and use it in GitHub Desktop.
Save SamatKadyrov/5b7c5485841019eac4526d878c0ed969 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Circumference : MonoBehaviour
{
[SerializeField] private Transform _target;
[SerializeField] private List<Transform> _surrounders;
[SerializeField] private float _radius;
private void Update()
{
float angleStep = 360 / _surrounders.Count * Mathf.Deg2Rad;
for (int i = 0; i < _surrounders.Count; i++)
{
float angle = angleStep * i;
Vector2 localPosition = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * _radius;
_surrounders[i].position = new Vector3(_target.position.x + localPosition.x,
_surrounders[i].position.y,
_target.position.z + localPosition.y);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment