Initial Commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SpawnCometsScript : MonoBehaviour {
|
||||
|
||||
public GameObject comet;
|
||||
public GameObject startPoint;
|
||||
public GameObject endPoint;
|
||||
public float delay;
|
||||
public float rateOfFire;
|
||||
public float radius;
|
||||
public float quantity;
|
||||
public float waves;
|
||||
|
||||
void Start () {
|
||||
StartCoroutine (SpawnVFX(comet, delay, rateOfFire));
|
||||
}
|
||||
|
||||
IEnumerator SpawnVFX (GameObject vfx, float delay, float rateDelay){
|
||||
for (int j = 0; j < waves; j++) {
|
||||
yield return new WaitForSeconds (delay);
|
||||
for (int i = 0; i < quantity; i++) {
|
||||
var startPos = startPoint.transform.position;
|
||||
if(radius != 0)
|
||||
startPos = new Vector3 (startPoint.transform.position.x + Random.Range (-radius, radius), startPoint.transform.position.y + Random.Range (-radius, radius), startPoint.transform.position.z + Random.Range (-radius, radius));
|
||||
GameObject objVFX = Instantiate (vfx, startPos, Quaternion.identity) as GameObject;
|
||||
|
||||
var endPos = endPoint.transform.position;
|
||||
if(radius != 0)
|
||||
endPos = new Vector3 (endPoint.transform.position.x + Random.Range (-radius, radius), endPoint.transform.position.y + Random.Range (-radius, radius), endPoint.transform.position.z + Random.Range (-radius, radius));
|
||||
RotateTo (objVFX, endPos);
|
||||
|
||||
yield return new WaitForSeconds (rateDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RotateTo (GameObject obj, Vector3 destination ) {
|
||||
var direction = destination - obj.transform.position;
|
||||
var rotation = Quaternion.LookRotation (direction);
|
||||
obj.transform.localRotation = Quaternion.Lerp (obj.transform.rotation, rotation, 1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cccff02035c20b44fb86ac5d9d7a74ea
|
||||
timeCreated: 1540304110
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,198 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SpawnMagicAbilityScript : MonoBehaviour {
|
||||
|
||||
[System.Serializable]
|
||||
public class ShakeParameters {
|
||||
public bool shake;
|
||||
public List<float> delays = new List<float>();
|
||||
}
|
||||
|
||||
public Text effectName;
|
||||
public GameObject cameras;
|
||||
public List<GameObject> VFXs = new List<GameObject> ();
|
||||
public List<ShakeParameters> VFXsShakeParameters = new List<ShakeParameters> ();
|
||||
|
||||
private int count = 0;
|
||||
private GameObject effectToSpawn;
|
||||
private ShakeParameters effectShakeParameters;
|
||||
private List<Camera> camerasList = new List<Camera> ();
|
||||
private Camera singleCamera;
|
||||
private List<GameObject> spawnedVFX = new List<GameObject>();
|
||||
|
||||
void Start () {
|
||||
|
||||
if (cameras.transform.childCount > 0) {
|
||||
for (int i = 0; i < cameras.transform.childCount; i++) {
|
||||
camerasList.Add (cameras.transform.GetChild (i).gameObject.GetComponent<Camera> ());
|
||||
}
|
||||
if(camerasList.Count == 0){
|
||||
Debug.Log ("Please assign one or more Cameras in inspector");
|
||||
}
|
||||
} else {
|
||||
singleCamera = cameras.GetComponent<Camera> ();
|
||||
if (singleCamera != null)
|
||||
camerasList.Add (singleCamera);
|
||||
else
|
||||
Debug.Log ("Please assign one or more Cameras in inspector");
|
||||
}
|
||||
|
||||
if (VFXs.Count > 0)
|
||||
effectToSpawn = VFXs [0];
|
||||
else
|
||||
Debug.Log ("No Effects added to the VFXs List");
|
||||
|
||||
if(VFXsShakeParameters.Count > 0)
|
||||
effectShakeParameters = VFXsShakeParameters [0];
|
||||
else
|
||||
Debug.Log ("No Delays added to the ShakeDelays List");
|
||||
|
||||
if (effectName != null)
|
||||
effectName.text = effectToSpawn.name;
|
||||
}
|
||||
|
||||
void Update () {
|
||||
if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0) )
|
||||
SpawnVFX ();
|
||||
if (Input.GetKeyDown (KeyCode.D))
|
||||
Next ();
|
||||
if (Input.GetKeyDown (KeyCode.A))
|
||||
Previous ();
|
||||
if (Input.GetKeyDown (KeyCode.C))
|
||||
SwitchCamera ();
|
||||
if (Input.GetKeyDown (KeyCode.X))
|
||||
ZoomIn ();
|
||||
if (Input.GetKeyDown (KeyCode.Z))
|
||||
ZoomOut ();
|
||||
}
|
||||
|
||||
public void SpawnVFX () {
|
||||
if (effectShakeParameters.shake && cameras != null)
|
||||
StartCoroutine (ShakeDelay (effectShakeParameters.delays));
|
||||
|
||||
GameObject vfxSpawned = Instantiate(effectToSpawn);
|
||||
spawnedVFX.Add(vfxSpawned);
|
||||
|
||||
var ps = GetFirstPS (vfxSpawned);
|
||||
}
|
||||
|
||||
public void Next () {
|
||||
count++;
|
||||
|
||||
CleanSpawnedVFXList();
|
||||
|
||||
if (count >= VFXs.Count)
|
||||
count = 0;
|
||||
|
||||
for (int i = 0; i < VFXs.Count; i++){
|
||||
if (count == i) {
|
||||
effectToSpawn = VFXs [i];
|
||||
effectShakeParameters = VFXsShakeParameters [i];
|
||||
}
|
||||
if (effectName != null) effectName.text = effectToSpawn.name;
|
||||
}
|
||||
}
|
||||
|
||||
public void Previous () {
|
||||
count--;
|
||||
|
||||
CleanSpawnedVFXList();
|
||||
|
||||
if (count < 0)
|
||||
count = VFXs.Count-1;
|
||||
|
||||
for (int i = 0; i < VFXs.Count; i++) {
|
||||
if (count == i) {
|
||||
effectToSpawn = VFXs [i];
|
||||
effectShakeParameters = VFXsShakeParameters [i];
|
||||
}
|
||||
if (effectName != null) effectName.text = effectToSpawn.name;
|
||||
}
|
||||
}
|
||||
|
||||
public void ZoomIn () {
|
||||
if (camerasList.Count > 0) {
|
||||
if (!camerasList [0].orthographic) {
|
||||
if (camerasList [0].fieldOfView < 101) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
camerasList [i].fieldOfView += 5;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (camerasList [0].orthographicSize < 10) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
camerasList [i].orthographicSize += 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ZoomOut () {
|
||||
if (camerasList.Count > 0) {
|
||||
if (!camerasList [0].orthographic) {
|
||||
if (camerasList [0].fieldOfView > 20) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
camerasList [i].fieldOfView -= 5;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (camerasList [0].orthographicSize > 4) {
|
||||
for (int i = 0; i < camerasList.Count; i++) {
|
||||
camerasList [i].orthographicSize -= 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SwitchCamera () {
|
||||
if (camerasList.Count > 0) {
|
||||
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);
|
||||
break;
|
||||
} else {
|
||||
camerasList [i + 1].gameObject.SetActive (true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ParticleSystem GetFirstPS (GameObject vfx){
|
||||
var ps = vfx.GetComponent<ParticleSystem> ();
|
||||
if (ps == null && vfx.transform.childCount > 0) {
|
||||
foreach (Transform t in vfx.transform) {
|
||||
ps = t.GetComponent<ParticleSystem> ();
|
||||
if(ps != null)
|
||||
return ps;
|
||||
}
|
||||
}
|
||||
return ps;
|
||||
}
|
||||
|
||||
IEnumerator ShakeDelay (List<float> delay){
|
||||
for (int i = 0; i < delay.Count; i++) {
|
||||
yield return new WaitForSeconds (delay[i]);
|
||||
//cameras.GetComponent<CameraShakeSimpleScript> ().ShakeCamera ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CleanSpawnedVFXList()
|
||||
{
|
||||
for (int i = 0; i < spawnedVFX.Count; i++)
|
||||
{
|
||||
Destroy(spawnedVFX[i]);
|
||||
}
|
||||
|
||||
spawnedVFX.Clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3042ba99f833e4942b7c9fab4deeb028
|
||||
timeCreated: 1541952525
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user