-
Notifications
You must be signed in to change notification settings - Fork 0
/
Orbit.cs
37 lines (31 loc) · 1.11 KB
/
Orbit.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Orbit : MonoBehaviour
{
public float rotateSpeed = 0;
public GameObject offcenterPrefab;
private int bulletMax;
// Start is called before the first frame update
void Start()
{
bulletMax = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>().bulletMax;
}
// Update is called once per frame
void Update()
{
transform.Rotate(new Vector3(0, 0 , rotateSpeed * Time.deltaTime), Space.Self);
}
public void addBullet()
{
GameObject newBullet = Instantiate(offcenterPrefab, gameObject.transform);
// And also rotate this offcenter bullet based the index of the newly created bullet (i.e. how many children there are -1)
int lastBulletIndex = transform.childCount - 1;
float rotationDiff = 360f / bulletMax;
newBullet.transform.localRotation = Quaternion.Euler(0, 0, rotationDiff * lastBulletIndex);
}
public void removeBullet()
{
Destroy(transform.GetChild(transform.childCount - 1).gameObject);
}
}