Hi guys, i’m having trouble with my invite and share buttons. unity won’t build due to not having overloads for the functions.
i’ve attached the script im using below so if anyone can help find the issue that would be great. i’ve highlighted the part of code which the compiler doesn’t like.
Here’s the facebook manager script
using UnityEngine;
using System.Collections;
public class FacebookManager {
public static bool IsInitialized = false;
public static string Permissions = "basic_info,publish_actions";
public static void Initialize() {
if(!IsInitialized) {
FB.Init(() => { IsInitialized = true; }, (bool IsGameShown) => {
if(!IsGameShown) {
Time.timeScale = 0;
} else {
Time.timeScale = 1;
}
});
}
}
public static bool IsAuthenticated {
get {
return FB.IsLoggedIn;
}
}
public static void Authenticate() {
if(IsAuthenticated) {
Debug.Log("Facebook is already authenticated!");
return;
}
FB.Login(Permissions, (FBResult result) => {
if(result.Error != null) {
Debug.Log("Facebook Login Error: " + result.Error);
}
});
}
this is what the compiler doesnt like for the invite function
public static void Invite(string inviteTitle, string inviteMessage) {
if(IsAuthenticated) {
FB.AppRequest(inviteMessage, null, “”, null, null, “”, inviteTitle, null);
} else {
AuthenticateAndInvite(inviteTitle, inviteMessage);
}
}
and this is what the compiler doesnt like for the share function
public static void Share(string name, string caption, string description, string image, string url) {
if(IsAuthenticated) {
FB.Feed(“”, url, name, caption, description, image, “”, “”, “”, “”, null, null);
} else {
AuthenticateAndShare(name, caption, description, image, url);
}
}
private static void AuthenticateAndInvite(string inviteTitle, string inviteMessage) {
if(IsAuthenticated) {
Debug.Log("Facebook is already authenticated!");
return;
}
FB.Login(Permissions, (FBResult result) => {
if(result.Error != null) {
Debug.Log("Facebook Login Error: " + result.Error);
} else if(IsAuthenticated) {
Invite(inviteTitle, inviteMessage);
}
});
}
private static void AuthenticateAndShare(string name, string caption, string description, string image, string url) {
if(IsAuthenticated) {
Debug.Log("Facebook is already authenticated!");
return;
}
FB.Login(Permissions, (FBResult result) => {
if(result.Error != null) {
Debug.Log("Facebook Login Error: " + result.Error);
} else if(IsAuthenticated) {
Share(name, caption, description, image, url);
}
});
}
}
Here is the invite script
using UnityEngine;
using System.Collections;
public class FacebookInvite : MonoBehaviour {
void Update () {
if(isTouched()) {
FacebookManager.Invite("Play Zombies with me!", "Check out this new game.");
}
}
public bool isTouched() {
bool result = false;
if(Input.touchCount == 1) {
if(Input.touches[0].phase == TouchPhase.Ended) {
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 touchPos = new Vector2(wp.x, wp.y);
if (collider2D == Physics2D.OverlapPoint(touchPos)) {
result = true;
}
}
}
if(Input.GetMouseButtonUp(0)) {
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos = new Vector2(wp.x, wp.y);
if (collider2D == Physics2D.OverlapPoint(mousePos)) {
result = true;
}
}
return result;
}
}
and here is the share script
using UnityEngine;
using System.Collections;
public class FacebookShare : MonoBehaviour {
void Update () {
if(isTouched()) {
FacebookManager.Share("Check out my latest run of zombies!", "I have a high score of " + (PlayerPrefs.GetInt("highscore", 0)).ToString() + " points. Can you beat me?");
}
}
public bool isTouched() {
bool result = false;
if(Input.touchCount == 1) {
if(Input.touches[0].phase == TouchPhase.Ended) {
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 touchPos = new Vector2(wp.x, wp.y);
if (collider2D == Physics2D.OverlapPoint(touchPos)) {
result = true;
}
}
}
if(Input.GetMouseButtonUp(0)) {
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos = new Vector2(wp.x, wp.y);
if (collider2D == Physics2D.OverlapPoint(mousePos)) {
result = true;
}
}
return result;
}
}
thanks in advanced