-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpawnObject.cs
50 lines (44 loc) · 1.38 KB
/
SpawnObject.cs
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
using UnityEngine;
public class SpawnObject : MonoBehaviour
{
// Start is called before the first frame update
[Header("生成物件/SpawnObject")]
public GameObject SpawnObj;
[Header("生成数量/SpawnNum")]
public int MinSpawnCount;
public int MaxSpawnCount;
int SpawnCount;
[Header("生成范围/SpawnArea")]
public BoxCollider2D boxcollider2d;
private void Awake()
{
boxcollider2d = GetComponent<BoxCollider2D>();
SpawnCount = Random.Range(MinSpawnCount, MaxSpawnCount);
}
private void Start()
{
int Spawncul = 0;
if (boxcollider2d)
{
while (Spawncul < SpawnCount)
{
Spawncul += 1;
Debug.Log(boxcollider2d.bounds.max);
float BoundPositionXLength = boxcollider2d.bounds.max.x;
float BoundPositionYLength = boxcollider2d.bounds.max.y;
Spawn(BoundPositionXLength, BoundPositionYLength);
}
}
}
void Spawn(float postionX, float PositonY)
{
float X = Random.RandomRange(0 - postionX, postionX);
float Y = Random.RandomRange(0 - PositonY, PositonY);
Vector3 spawnvector =new Vector3(X, Y,0);
SpawnObj.transform.position = spawnvector;
Instantiate(SpawnObj,SpawnObj.transform);
Debug.Log(X);
Debug.Log(Y);
}
}