playMaker

Author Topic: Calling a Global event from script (solved)  (Read 619 times)

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Calling a Global event from script (solved)
« on: October 04, 2020, 01:38:59 PM »
My character has a reset on death script.

I would like to call a Global event "You Died"

However, I am not sure how to do this could someone help?

Code: [Select]
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace XXX-XX
{
    /// <summary>
    /// Reset the level on character's death.
    /// </summary>
    public class ResetOnDeath : MonoBehaviour, ICharacterHealthListener
    {
        /// <summary>
        /// Time in seconds to reset the level after character's death
        /// </summary>
        [Tooltip("Time in seconds to reset the level after character's death")]
        public float Delay = 3.0f;

        /// <summary>
        /// Starts a sequence to reset the level after waiting for Delay.
        /// </summary>
        public void OnDead()
        {
            StartCoroutine(delayedReset());
        }

        public void OnResurrect() { }

        private IEnumerator delayedReset()
        {
            yield return new WaitForSeconds(Delay);
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }

        private void OnValidate()
        {
            Delay = Mathf.Max(0, Delay);
        }
    }
}


I have come to see that this is not the correct approach, but thanks anyway.
« Last Edit: October 06, 2020, 12:08:43 PM by colpolstudios »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Calling a Global event from script
« Reply #1 on: October 06, 2020, 11:24:10 AM »
Hi.
maybe the playmaker api can help.

https://hutonggames.fogbugz.com/default.asp?W127

on the bottom are some examples.

Not sure if there is a global event on the sample.
But you could send a event to a object/fsm and from there do a global if needed.