River Jiang
2020-10-27 1f5eda1c9d22a3676298751c7282a5874f13bed0
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class SpawnProjectilesScript : MonoBehaviour {
 
    public bool cameraShake;
    public Text effectName;
    public RotateToMouseScript rotateToMouse;
    public GameObject firePoint;
    public GameObject cameras;
    public List<GameObject> VFXs = new List<GameObject> ();
 
    private int count = 0;
    private float timeToFire = 0f;
    private GameObject effectToSpawn;
    private List<Camera> camerasList = new List<Camera> ();
 
    void Start () {
        
        for (int i = 0; i < cameras.transform.childCount; i++) {
            camerasList.Add (cameras.transform.GetChild(i).gameObject.GetComponent<Camera>());
        }
 
        Application.targetFrameRate = 60;
        effectToSpawn = VFXs[0];
        if (effectName != null) effectName.text = effectToSpawn.name;
 
        rotateToMouse.SetCamera (camerasList [2]);
        rotateToMouse.StartUpdateRay ();
    }
 
    void Update () {
        if (Input.GetKey (KeyCode.Space) && Time.time >= timeToFire || Input.GetMouseButton (0) && Time.time >= timeToFire) {
            timeToFire = Time.time + 1f / effectToSpawn.GetComponent<ProjectileMoveScript>().fireRate;
            SpawnVFX ();    
        }
 
        if (Input.GetKeyDown (KeyCode.D))
            Next ();
        if (Input.GetKeyDown (KeyCode.A)) 
            Previous ();    
        if (Input.GetKeyDown (KeyCode.C))
            SwitchCamera ();    
        if (Input.GetKeyDown (KeyCode.Alpha1))
            CameraShake ();
        if (Input.GetKeyDown (KeyCode.X))
            ZoomIn ();
        if (Input.GetKeyDown (KeyCode.Z))
            ZoomOut ();
    }
 
    public void SpawnVFX () {
        GameObject vfx;
 
        if (cameraShake && cameras != null)
            cameras.GetComponent<CameraShakeSimpleScript> ().ShakeCamera ();
 
        if (firePoint != null) {
            vfx = Instantiate (effectToSpawn, firePoint.transform.position, Quaternion.identity);
            if(rotateToMouse != null){
                vfx.transform.localRotation = rotateToMouse.GetRotation ();
            } 
            else Debug.Log ("No RotateToMouseScript found on firePoint.");
        }
        else
            vfx = Instantiate (effectToSpawn);
 
        var ps = vfx.GetComponent<ParticleSystem> ();
 
        if (vfx.transform.childCount > 0) {
            ps = vfx.transform.GetChild (0).GetComponent<ParticleSystem> ();
        }
    }
 
    public void Next () {
        count++;
 
        if (count > VFXs.Count)
            count = 0;
 
        for(int i = 0; i < VFXs.Count; i++){
            if (count == i)    effectToSpawn = VFXs [i];
            if (effectName != null)    effectName.text = effectToSpawn.name;
        }
    }
 
    public void Previous () {
        count--;
 
        if (count < 0)
            count = VFXs.Count;
 
        for (int i = 0; i < VFXs.Count; i++) {
            if (count == i) effectToSpawn = VFXs [i];
            if (effectName != null)    effectName.text = effectToSpawn.name;
        }
    }
 
    public void CameraShake () {
        cameraShake = !cameraShake;
    }
 
    public void ZoomIn () {
        for (int i = 0; i < camerasList.Count; i++) {
            camerasList [i].fieldOfView += 5;
        }
    }
 
    public void ZoomOut () {
        for (int i = 0; i < camerasList.Count; i++) {
            camerasList [i].fieldOfView -= 5;
        }
    }
 
    public void SwitchCamera () {
        for (int i = 0; i < camerasList.Count; i++) {
            if (camerasList [i].gameObject.activeSelf) {
                camerasList [i].gameObject.SetActive (false);
                if ((i+1) == camerasList.Count) {
                    camerasList [0].gameObject.SetActive (true);
                    rotateToMouse.SetCamera(camerasList [0]);
                    break;
                } else {
                    camerasList [i+1].gameObject.SetActive (true);
                    rotateToMouse.SetCamera(camerasList [i+1]);
                    break;
                }
            }
        }
    }
}