hi
I just can’t figure out why my script isn’t working and need your help.
I’ve attached both scripts to seperate game objects and dragged the object with the Trigger script to the trigger property of the game object with the Triggered script.
My problem is that in the console I only get “TestOne” as output and not “TestOne” and “TestTwo”.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
[System.Serializable]
public class myEvent : UnityEvent<bool> { }
public class Trigger : MonoBehaviour
{
public UnityEvent eventOne;
public myEvent eventTwo;
void Start()
{
eventTwo = new myEvent();
}
void Update()
{
eventOne.Invoke();
eventTwo.Invoke(true);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class Triggered : MonoBehaviour
{
public Trigger trigger;
public UnityAction actionOne;
public UnityAction<bool> actionTwo;
private void Start()
{
trigger.eventOne.AddListener(Test);
//NOT WOKING
trigger.eventTwo.AddListener(actionTwo);
actionTwo += Test;
}
public void Test()
{
Debug.Log("TestOne");
}
public void Test(bool state)
{
Debug.Log("TestTwo");
}
}