I need to add Object into Event, then use script function (with param.). I want to understand the code and codes which is on this site is for me a little bit hard to understand. Can anyone help me?
(I don’t need to create new Event type or item to event type - that’s already created)
Hi, This is how we access Event Trigger from Script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class triggerAtRuntime: MonoBehaviour {
// use the editor to grab the event Trigger component
public EventTrigger trigger;
// Use this for initialization
void Start()
{
//Or use GetComponent<EventTrigger>( ) if EventTrigger is attached to same GameObject
trigger = GetComponent<EventTrigger>( );
EventTrigger.Entry entry = new EventTrigger.Entry( );
entry.eventID = EventTriggerType.PointerDown;
entry.callback.AddListener( ( data ) => { OnPointerDownDelegate( ( PointerEventData ) data ); } );
trigger.triggers.Add( entry );
}
public void OnPointerDownDelegate( PointerEventData data )
{
foo( 100,"Hello World" );
}
void foo (int a, string b) {
Debug.Log( a + " " + b );
}
}