How to pass an anonymous function as parameter to onclick method C#

112 views Asked by At

Using Unity 5.4 and FB SDK 7.9 I want to use the onclick button functionality to run the method Share. This method has many parameters, so I need to create the onclick functionality in code and not in the inspector. I am getting the error unexpected symbol link parameter expecting '.' What is going on? How can I fix this?

public class FBScript : MonoBehaviour {

    public Button PostBtn;

    void Start() {
        Button btn = PostBtn.GetComponent<Button>();
        btn.onClick.AddListener(delegate {
            Share(string linkParameter, string namerParameter, string captionParameter, string descriptionParameter, string pictureParameter, string redirectParameter);
        });
    }

    void Awake () {
        FB.Init(SetInit, OnHideUnity);
    }

    void SetInit () {
        if (FB.IsLoggedIn) {
            Debug.Log("FB is Logged In");
        } else {
            Debug.Log("FB is not Logged In");
        }
    }

    void OnHideUnity(bool isGameShown) {
        if (!isGameShown) {
            Time.timeScale = 0;
        } else {
            Time.timeScale = 1;
        }
    }

    public void FBLogin() {
        List<string> permissions = new List<string>();
        permissions.Add("public_profile");
        FB.LogInWithReadPermissions(permissions, AuthCallBack);
    }

    void AuthCallBack(ILoginResult result) {
        if (result.Error != null) {
            Debug.Log(result.Error);
        } else {
            if (FB.IsLoggedIn) {
                Debug.Log("FB is Logged In");
            } else {
                Debug.Log("FB is not Logged In");
            }
        }
    }

    private const string FACEBOOK_APP_ID = "999999999999999";
    private const string FACEBOOK_URL = "http://www.facebook.com/dialog/feed";

    public void Share(string linkParameter, string namerParameter, string captionParameter, string descriptionParameter, string  pictureParameter, string redirectParameter) {
        Application.OpenURL(FACEBOOK_URL + "?app_id=" + FACEBOOK_APP_ID + 
        "&link=" + WWW.EscapeURL(linkParameter) +
        "&name=" + WWW.EscapeURL(namerParameter) +
        "&caption=" + WWW.EscapeURL(captionParameter) +
        "&description=" + WWW.EscapeURL(descriptionParameter) +
        "&picture=" + WWW.EscapeURL(pictureParameter) +
        "&redirect_url=" + WWW.EscapeURL(redirectParameter));
    }
}
0

There are 0 answers