created victory object and level progression
also tried to create a way to launch the game from any scene, but it doesn't really work. don't use anything in the folder called "DEBUG"
This commit is contained in:
@@ -6,6 +6,8 @@ public class ProjectileEnemy : MonoBehaviour {
|
||||
|
||||
[SerializeField] GameObject projectile;
|
||||
[SerializeField] GameObject firePoint;
|
||||
[SerializeField] [Range(0.1f, 3f)] float fireSpeed;
|
||||
[SerializeField] float projectileSpeed;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
@@ -13,9 +15,9 @@ public class ProjectileEnemy : MonoBehaviour {
|
||||
}
|
||||
|
||||
IEnumerator Fire() {
|
||||
yield return new WaitForSeconds(3f);
|
||||
yield return new WaitForSeconds(1/fireSpeed);
|
||||
GameObject newProjectile = Instantiate(projectile, firePoint.transform.position, firePoint.transform.rotation);
|
||||
newProjectile.GetComponent<Rigidbody2D>().AddRelativeForce(new Vector2(80, 0));
|
||||
newProjectile.GetComponent<Rigidbody2D>().AddRelativeForce(new Vector2(projectileSpeed, 0));
|
||||
newProjectile.transform.Rotate(new Vector3(0,0,-90));
|
||||
StartCoroutine(Fire());
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ public class StateController : MonoBehaviour {
|
||||
[Header("Enemies")]
|
||||
GameObject[] enemiesInScene;
|
||||
|
||||
[Header("LevelProgression")]
|
||||
GameObject victoryCanvas;
|
||||
|
||||
void Awake() {
|
||||
// check to see if a state controller already exists
|
||||
if (GameObject.FindGameObjectWithTag("StateController") != null) {
|
||||
@@ -33,7 +36,7 @@ public class StateController : MonoBehaviour {
|
||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
|
||||
if (inDebugMode) {
|
||||
debugCanvas = GameObject.Find("DebugCanvas");
|
||||
debugCanvas = GameObject.FindGameObjectWithTag("DebugCanvas");
|
||||
debugCanvas.SetActive(false);
|
||||
}
|
||||
}
|
||||
@@ -53,6 +56,13 @@ public class StateController : MonoBehaviour {
|
||||
TogglePauseMenu(false);
|
||||
}
|
||||
|
||||
victoryCanvas = GameObject.Find("VictoryCanvas");
|
||||
if (victoryCanvas != null) {
|
||||
Button continueButton = GameObject.Find("ContinueButton").GetComponent<Button>();
|
||||
continueButton.onClick.AddListener(ContinueToNextLevel);
|
||||
victoryCanvas.SetActive(false);
|
||||
}
|
||||
|
||||
// keep track of all enemies
|
||||
enemiesInScene = GameObject.FindGameObjectsWithTag("Enemy");
|
||||
// print(enemiesInScene);
|
||||
@@ -107,4 +117,12 @@ public class StateController : MonoBehaviour {
|
||||
public void SetDeathCanvasActive(bool activeState) {
|
||||
deathCanvas.SetActive(activeState);
|
||||
}
|
||||
|
||||
public void ShowVictoryCanvas() {
|
||||
victoryCanvas.SetActive(true);
|
||||
}
|
||||
|
||||
public void ContinueToNextLevel() {
|
||||
GameObject.FindGameObjectWithTag("SceneManager").GetComponent<SceneController>().NextScene();
|
||||
}
|
||||
}
|
||||
|
||||
30
Assets/Scripts/VictoryObjectBehavior.cs
Normal file
30
Assets/Scripts/VictoryObjectBehavior.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class VictoryObjectBehavior : MonoBehaviour
|
||||
{
|
||||
public float height = 1f;
|
||||
public float speed = 1f;
|
||||
Vector2 initPosition;
|
||||
|
||||
void Awake() {
|
||||
initPosition = this.transform.position;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
transform.position = new Vector2(initPosition.x, initPosition.y + Mathf.Sin(Time.time * speed) * height);
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.DrawLine(new Vector3(transform.position.x, transform.position.y - height, transform.position.z), new Vector3(transform.position.x, transform.position.y + height, transform.position.z));
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col) {
|
||||
if (col.tag == "Player") {
|
||||
GameObject.FindGameObjectWithTag("StateController").GetComponent<StateController>().ShowVictoryCanvas();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/VictoryObjectBehavior.cs.meta
Normal file
11
Assets/Scripts/VictoryObjectBehavior.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a22e1f323783642f398cdf2ed3adcafa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user