blob: b8ce07b5b1ad7814b6c310d78f65dea5748712fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Ì«¿ÕÉäÏß
/// </summary>
public class TestSpaceBeam : MonoBehaviour
{
[SerializeField] private GameObject m_Beam;
TopDownTransform m_Coord;
List<GameObject> m_Beams = new List<GameObject>();
float m_RotateSpeed = 5f;
float m_Radius = 1f;
int count = 8;
float m_CurrentAngle = 0;
private void Awake()
{
m_Coord = GetComponent<TopDownTransform>();
}
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<GameObject>(m_Beam, this.transform);
beam.GetComponent<TopDownTransform>().localPosition = pos;
beam.SetActive(true);
m_Beams.Add(beam);
}
}
void Update()
{
m_CurrentAngle += m_RotateSpeed * Time.deltaTime;
RotateBeams(m_CurrentAngle);
}
/// <summary>
/// Ðýת
/// </summary>
/// <param name="angle">»¡¶È</param>
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<TopDownTransform>().localPosition = pos;
}
}
}
|