Search Unity

Mana Gloom

Discussion in 'Made With Unity' started by sarynth, Jan 19, 2021.

  1. sarynth

    sarynth

    Joined:
    May 16, 2017
    Posts:
    98
    Just posted v1.0.7 to Steam. Check that link out for the release notes. Having a blast developing this in Unity.

    If you are interested in the game, wishlist Mana Gloom on Steam, but wait for two weeks to buy it!

    Steam won't let me lower the price. Currently at $11.99, I'm lowering it to $5.99 as soon as the 30 days pass.



    Added a new spell, and some new content. Really happy with how this is progressing. Let me know if you have any questions, I'd be happy to answer them.



    And, here's another shot of the new procedurally generated dungeons.

     
    Amon and adamgolden like this.
  2. sarynth

    sarynth

    Joined:
    May 16, 2017
    Posts:
    98
    This is not released yet, but added some mushroom traps.



    Was having a slow day, decided I had to get something done. This seemed simple enough, wrote this whole file this evening. (Leveraging the rest of my game's code base of course.)

    One simple yet fun thing I did was rotate each one randomly, and pick from one of three random meshes. So the pile of exploding mushrooms to the top left that each look a little different is all the same prefab.

    Code for reference if interested.

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using Combat;
    3. using Creatures.Hero;
    4. using DarkTonic.MasterAudio;
    5. using Sirenix.OdinInspector;
    6. using UnityEngine;
    7.  
    8. namespace Basics.Mechanics
    9. {
    10.     public class ExplodingTrap : MonoBehaviour
    11.     {
    12.         [BoxGroup("Stats")]
    13.         public float shakeAmplitude = 0.02f;
    14.  
    15.         [BoxGroup("Stats")]
    16.         public float damageRadius = 5;
    17.  
    18.         [BoxGroup("Stats")]
    19.         public float criticalRadius = 2.5f;
    20.  
    21.         [BoxGroup("Damage")]
    22.         public int damageMin;
    23.  
    24.         [BoxGroup("Damage")]
    25.         public int damageMax;
    26.  
    27.         [BoxGroup("Damage")]
    28.         public float criticalMultiplier = 2f;
    29.  
    30.         [BoxGroup("Prefabs")]
    31.         [SoundGroup]
    32.         public string explosionSound;
    33.  
    34.         [BoxGroup("Prefabs")]
    35.         public ParticleSystem explosionParticle;
    36.  
    37.         [BoxGroup("Prefabs")]
    38.         public List<Mesh> randomMeshes;
    39.  
    40.         private Vector3 _originalPosition;
    41.         private Vector3 _originalScale;
    42.  
    43.         private Transform _transform;
    44.  
    45.         private bool _trapActivated;
    46.         private bool _trapExploded;
    47.  
    48.         private float _scale = 1;
    49.  
    50.         private void Start()
    51.         {
    52.             _transform = transform;
    53.             _originalPosition = _transform.position;
    54.             _originalScale = _transform.localScale;
    55.  
    56.             // Randomize the appearance (rotation and mesh.)
    57.             _transform.Rotate(0.0f, 0.0f, Random.Range(0.0f, 360.0f));
    58.  
    59.             GetComponent<MeshFilter>().mesh = randomMeshes[Random.Range(0, randomMeshes.Count)];
    60.         }
    61.  
    62.         private void OnTriggerEnter(Collider other)
    63.         {
    64.             // If the trap has already activated, or this is not the player, then we don't care.
    65.             if (_trapActivated || !other.CompareTag("Player"))
    66.             {
    67.                 return;
    68.             }
    69.  
    70.             _trapActivated = true;
    71.         }
    72.  
    73.         private void Update()
    74.         {
    75.             // If trap has not been activated, or it has already exploded, we don't care.
    76.             if (!_trapActivated || _trapExploded)
    77.             {
    78.                 return;
    79.             }
    80.  
    81.             if (_scale > 3f)
    82.             {
    83.                 _trapExploded = true;
    84.  
    85.                 // Deal damage if player is close enough.
    86.                 CheckPlayerHit();
    87.  
    88.                 // The noise at the position.
    89.                 MasterAudio.PlaySound3DAtVector3AndForget(explosionSound, _originalPosition);
    90.  
    91.                 // Pretty effects.
    92.                 var explosion = Instantiate(explosionParticle, _originalPosition + Vector3.up, Quaternion.identity);
    93.                 Destroy(explosion, 3f);
    94.  
    95.                 // Destroy the mushroom.
    96.                 Destroy(gameObject);
    97.                 return;
    98.             }
    99.  
    100.             _scale += Time.deltaTime;
    101.  
    102.             _transform.localScale = _originalScale * _scale;
    103.             _transform.position = _originalPosition + Random.insideUnitSphere * (shakeAmplitude * _scale);
    104.         }
    105.  
    106.         private void CheckPlayerHit()
    107.         {
    108.             // Since these are "live" in the map now, we need to check for the hero each tick.
    109.             var hero = HeroManager.Instance.Hero;
    110.             if (!hero || hero.isDead)
    111.             {
    112.                 return;
    113.             }
    114.  
    115.             // Check if hero is within range.
    116.             var dist = (hero.transform.position - transform.position).magnitude;
    117.             if (dist > damageRadius)
    118.             {
    119.                 return;
    120.             }
    121.  
    122.             // If they are within critical radius, apply critical damage.
    123.             var isCritical = dist < criticalRadius;
    124.  
    125.             hero.Damage(damageMin, damageMax)
    126.                 .Critical(isCritical ? 1.0f : 0.0f, criticalMultiplier)
    127.                 .Apply();
    128.         }
    129.  
    130.         private void OnDrawGizmosSelected()
    131.         {
    132.             Gizmos.DrawSphere(transform.position, damageRadius);
    133.         }
    134.     }
    135. }
    136.