Skip to content

Commit e47fbbf

Browse files
authored
Added script to generate iterms
1 parent 6faabb3 commit e47fbbf

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

GenItems.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class GenItems : MonoBehaviour
6+
{
7+
public Rigidbody prefab; //TODO: change to powerup or item class when class exists
8+
private Vector3 spawnPos;
9+
private Vector3 velocity;
10+
// Start is called before the first frame update
11+
void Start()
12+
{
13+
spawnPos = this.transform.position;
14+
spawnPos.z += 50; //will be 50m away
15+
InvokeRepeating("createPowerUp", 0.5f, 2.0f);
16+
}
17+
18+
// Update is called once per frame
19+
void Update()
20+
{
21+
spawnPos = this.transform.position;
22+
spawnPos.z += 50; //will be 50m away
23+
}
24+
25+
void createPowerUp()
26+
{
27+
Quaternion rotate = Quaternion.Euler(Random.Range(-15.0f, 15.0f), Random.Range(-15.0f, 15.0f),0);
28+
Rigidbody powerUp = Instantiate(prefab, new Vector3(spawnPos.x, spawnPos.y, spawnPos.z), Quaternion.identity);
29+
powerUp.velocity = rotate * (new Vector3(0f,0f,Random.Range(-20.0f, -10.0f)));
30+
Destroy(powerUp.gameObject, 5.0f);
31+
}
32+
}

0 commit comments

Comments
 (0)