Created
December 5, 2023 18:04
-
-
Save SamatKadyrov/5b7c5485841019eac4526d878c0ed969 to your computer and use it in GitHub Desktop.
This file contains 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 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