using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// Ì«¿ÕÉäÏß /// public class TestSpaceBeam : MonoBehaviour { [SerializeField] private GameObject m_Beam; TopDownTransform m_Coord; List m_Beams = new List(); float m_RotateSpeed = 5f; float m_Radius = 1f; int count = 8; float m_CurrentAngle = 0; private void Awake() { m_Coord = GetComponent(); } public void Set(Vector3 posTDS) { m_Coord.position = posTDS; Vector3 groundPos = m_Coord.positionOnGround; for(int i = 0; i < count; ++i) { float angle = Mathf.PI * 2f / (float)count * i; Vector3 pos = /*groundPos +*/ new Vector3(m_Radius * Mathf.Cos(angle), m_Radius * Mathf.Sin(angle), 0f); GameObject beam = Instantiate(m_Beam, this.transform); beam.GetComponent().localPosition = pos; beam.SetActive(true); m_Beams.Add(beam); } } void Update() { m_CurrentAngle += m_RotateSpeed * Time.deltaTime; RotateBeams(m_CurrentAngle); } /// /// Ðýת /// /// »¡¶È void RotateBeams(float angle) { Vector3 groundPos = m_Coord.positionOnGround; for (int i = 0; i < m_Beams.Count; ++i) { float rad = angle + Mathf.PI * 2f / (float)count * i; Vector3 pos = /*groundPos + */new Vector3(m_Radius * Mathf.Cos(rad), m_Radius * Mathf.Sin(rad), 0f); m_Beams[i].GetComponent().localPosition = pos; } } }