Hi guys,
I was wondering if its possible to get the same result in C# as I have with Java:
https://www.screencast.com/t/p6yFCX9b
I’m trying to create a new instance of a object in a parameter of the submit function and overwrite the execute() function.
I can’t really find any solutions to this, so I hope that anyone here can help me.
Thanks in advance!
I don’t know if the following will fit your needs, but you could use delegates to do this :
using UnityEngine;
using System;
using System.Collections;
public class MyClass
{
private Action action;
// Default constructor : Use the default function
public MyClass()
{
this.action = DefaultAction;
RunAction() ;
}
// Overloaded constructor : use the given function
public MyClass( Action action )
{
this.action = action;
RunAction() ;
}
public void RunAction()
{
this.action.Invoke();
}
private void DefaultAction()
{
Debug.Log( "Hello world" );
}
}
For anyone looking for the same answer, i did it on this way:
https://www.screencast.com/t/x7DzSqUM