Stealth TDS

Over dit spel...

Het doel is om het level door te komen, vijanden te ontwijken of te stunnen en de blauwe eindbaas weer naar het begin mee te slepen.

Alle controls in het spel worden uitgelegd door de tutorial aan het begin, perfect om je klaar te stomen voor het geheim agent leven natuurlijk!

Het spel heeft ook een save systeem dat momenteel alleen saved voor de speelsessie, maar zou ook uitgebreid kunnen worden om permanent opgeslagen te worden.

Engine: Unity/C#
Platform: Windows

StunStick.cs

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class StunStick : MonoBehaviour
{
    GameObject touching;
    [SerializeField]
    GameObject halo;
    [SerializeField]
    ParticleSystem particlesConstant;
    [SerializeField]
    AudioSource audioSource;

    bool charging = false;
    [SerializeField]
    float maxCharge;
    float chargeTimer;

    //UI
    [SerializeField]
    GameObject[] menuBars;
    [SerializeField]
    Color normalColor, chargedColor;

    public enum ParticleState
    {
        Charging,
        Emit,
        Stop
    }
    ParticleState particleState = ParticleState.Stop;
    public ParticleState PState
    {
        get { return particleState; }
        set { particleState = value; }
    }

    void Start()
    {
        chargeTimer = maxCharge;
    }

    void Update()
    {
        if (particleState == ParticleState.Charging && chargeTimer > 0)
        {
            particlesConstant.emissionRate += 200/maxCharge * Time.deltaTime;
            chargeTimer -= Time.deltaTime;
            Debug.Log(chargeTimer);
        }

        else if (particleState == ParticleState.Charging)
        {
            Debug.Log("Full");
             foreach(GameObject bar in menuBars)
             {
                 bar.GetComponent().color = Color.Lerp(bar.GetComponent().color, chargedColor, 20 * Time.deltaTime);
             }
        }

        else
        {
            foreach (GameObject bar in menuBars)
            {
                bar.GetComponent().color = Color.Lerp(bar.GetComponent().color, normalColor, 20 * Time.deltaTime);
            }
        }

        if (particleState == ParticleState.Emit)
        {
            Stun();
            particlesConstant.Emit(250);
            particleState = ParticleState.Stop;
        }

        if (particleState == ParticleState.Stop)
        {
            particlesConstant.emissionRate = 0;
            particlesConstant.Stop();
            chargeTimer = maxCharge;
        }

        menuBars[1].transform.localScale = Vector3.Lerp(menuBars[1].transform.localScale, new Vector3(particlesConstant.emissionRate / 100, menuBars[1].transform.localScale.y, menuBars[1].transform.localScale.z), 5 * Time.deltaTime);
        menuBars[2].transform.position = Vector3.Lerp(menuBars[2].transform.position, new Vector3(58 + particlesConstant.emissionRate, menuBars[2].transform.position.y, menuBars[2].transform.position.z), 5 * Time.deltaTime);
        
    }

    void OnTriggerEnter(Collider collision)
    {
        if (collision.gameObject.tag == "Enemy")
        {
            halo.SetActive(true);
            touching = collision.gameObject;
            Debug.Log("Touched an enemy");
        }
    }

    void OnTriggerExit(Collider collision)
    {
        if (collision.gameObject == touching)
        {
            halo.SetActive(false);
            touching = null;
            Debug.Log("Touching is now null");
        }
    }

    public void Stun()
    {
        //particles.Play();
        audioSource.Play();

        if (touching != null)
        {
            touching.GetComponent().GetStunned(transform.position);
        }
    }

    public void StunCharge()
    {
        particlesConstant.Play();
        particlesConstant.emissionRate = 0;
        chargeTimer = maxCharge;
        particleState = ParticleState.Charging;
    }

    public void StunChargeStop()
    {
        if (chargeTimer > 0)
        {
            particleState = ParticleState.Stop;
        }
        else
        {
            particleState = ParticleState.Emit;
        }
    }
}

Downloads

Windows
Source