Skip to content

Commit

Permalink
FEAT: #25 宝石を複数生成できるようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
yigedinglia committed Jan 14, 2022
1 parent c8ee650 commit da06b88
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
14 changes: 13 additions & 1 deletion Assets/Prototypes/#25-GemScatter/GemSpawnTest.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,10 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 719865656}
m_Modifications:
- target: {fileID: 7641956194905182684, guid: 51e3be7b71a6b114abc41635abae258e, type: 3}
propertyPath: SpawnNum
value: 4
objectReference: {fileID: 0}
- target: {fileID: 7641956194905182684, guid: 51e3be7b71a6b114abc41635abae258e, type: 3}
propertyPath: SpawnSpeed
value: 1000
Expand Down Expand Up @@ -8706,7 +8710,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 727615474137205831, guid: a58e9cab4f08c714ca0bd0bd66b0a050, type: 3}
propertyPath: m_LocalPosition.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 727615474137205831, guid: a58e9cab4f08c714ca0bd0bd66b0a050, type: 3}
propertyPath: m_LocalPosition.z
Expand Down Expand Up @@ -8740,6 +8744,14 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 727615474137205944, guid: a58e9cab4f08c714ca0bd0bd66b0a050, type: 3}
propertyPath: m_Depth
value: -1
objectReference: {fileID: 0}
- target: {fileID: 727615474137205944, guid: a58e9cab4f08c714ca0bd0bd66b0a050, type: 3}
propertyPath: orthographic size
value: 2.09
objectReference: {fileID: 0}
- target: {fileID: 727615474137205947, guid: a58e9cab4f08c714ca0bd0bd66b0a050, type: 3}
propertyPath: m_Name
value: Main Camera
Expand Down
17 changes: 14 additions & 3 deletions Assets/Scripts/Runtime/Gem/GemSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class GemSpawner : MonoBehaviour
public Vector3 SpawnPosOffset;
public float SpawnSpeed;
public float SpawnInterval;
public int SpawnNum;
public float SpawnEachGemOffset;

private float m_SpawnTimer;

Expand All @@ -24,10 +26,19 @@ void Spawn()
m_SpawnTimer += Time.deltaTime;
if(m_SpawnTimer > SpawnInterval)
{
GameObject obj = GemPool.Instance.Spawn("Gem", transform.position + SpawnPosOffset, transform.rotation);
if (obj && obj.TryGetComponent(out Rigidbody2D rigidbody))
for(int i = 0; i < SpawnNum; i++)
{
rigidbody.AddForce(new Vector2(transform.up.x, transform.up.z) * SpawnSpeed);
Vector3 pos = Vector3.zero;
float _randomValueX = Random.Range(-0.5f, 0.5f);
float _randomValueY = Random.Range(-0.5f, 0.5f);
pos.x = _randomValueX + transform.position.x;
pos.y = _randomValueY + transform.position.y;
GameObject obj = GemPool.Instance.Spawn("Gem", pos, transform.rotation);
if (obj && obj.TryGetComponent(out Rigidbody2D rigidbody))
{
float _SpawnSpeed = SpawnSpeed * Random.Range(0.9f, 1.1f);
rigidbody.AddForce(new Vector2(transform.up.x, transform.up.z) * SpawnSpeed);
}
}
m_SpawnTimer = 0;
}
Expand Down

0 comments on commit da06b88

Please sign in to comment.