Hey guys, hopefully a simple answer will come from this, but, basically I made a game in javascript, but need to use a C# Bridge Script to associate my original scripts to the Facebook SDK C# Scripts. All I want to do is increase a PlayerPref value by a certain amount depending on what day it is.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class FacebookTrigger : MonoBehaviour {
public static int reward = 0;
public static GameObject fbShareButton = GameObject.Find ("FacebookShareButton");
// Use this for initialization
void Start () {
}
public static void ResetButton() {
PlayerPrefs.SetFloat("RetryTokens", PlayerPrefs.GetFloat("RetryTokens") + reward);
reward = 0;
//GameObject fbButton = GameObject.Find ("FacebookShareButton");
Texture2D texd = (Texture2D)Resources.Load("Textures/ShareToFacebook", typeof(Texture2D));
fbShareButton.renderer.material.mainTexture = texd;
}
void CheckAndSetDate () {
if (System.DateTime.Now.DayOfYear == 1) {
//NewYearsDay
reward = 5;
} else if (System.DateTime.Now.DayOfYear == 19) {
//MartinLutherKingDay
reward = 3;
} else if (System.DateTime.Now.DayOfYear == 45) {
//ValentinesDay
reward = 3;
} else if (System.DateTime.Now.DayOfYear == 47) {
//PresidentsDay
reward = 3;
} else if (System.DateTime.Now.DayOfYear == 76) {
//StPatricksDay
reward = 3;
} else if (System.DateTime.Now.DayOfYear == 91) {
//AprilFoolsDay
reward = 5;
} else if (System.DateTime.Now.DayOfYear == 95) {
//Easter
reward = 3;
} else if (System.DateTime.Now.DayOfYear == 125) {
//CincoDeMaioDay
reward = 3;
} else if (System.DateTime.Now.DayOfYear == 130) {
//MothersDay
reward = 3;
} else if (System.DateTime.Now.DayOfYear == 185) {
//July4th
reward = 5;
} else if (System.DateTime.Now.DayOfYear == 197) {
//VexBirthday
reward = 5;
} else if (System.DateTime.Now.DayOfYear == 215) {
//WatermelonDay
reward = 3;
} else if (System.DateTime.Now.DayOfYear == 244) {
//LaborDay
reward = 5;
} else if (System.DateTime.Now.DayOfYear == 254) {
//9/11
reward = 5;
} else if (System.DateTime.Now.DayOfYear == 285) {
//ColumbusDay
reward = 3;
} else if (System.DateTime.Now.DayOfYear == 304) {
//Halloween
reward = 5;
} else if (System.DateTime.Now.DayOfYear == 315) {
//VetransDay
reward = 3;
} else if (System.DateTime.Now.DayOfYear == 330) {
//ThanksGivingDay
reward = 5;
} else if (System.DateTime.Now.DayOfYear == 358) {
//ChristmasEve
reward = 3;
} else if (System.DateTime.Now.DayOfYear == 359) {
//CristmasDay
reward = 5;
} else if (System.DateTime.Now.DayOfYear == 365) {
//NewyearsEve
reward = 5;
} else {
reward = 1;
}
if (PlayerPrefs.GetFloat ("LastDay") < System.DateTime.Now.DayOfYear) {
PlayerPrefs.SetFloat ("LastDay", System.DateTime.Now.DayOfYear);
} else if (PlayerPrefs.GetFloat("LastDay") > System.DateTime.Now.DayOfYear) {
//New YEAR
PlayerPrefs.SetFloat ("LastDay", System.DateTime.Now.DayOfYear);
}
}
void Awake () {
// Initialize FB SDK
//GameObject fbShareButton = GameObject.Find ("FacebookShareButton");
CheckAndSetDate ();
if (reward == 0) {
Texture2D tex0 = (Texture2D)Resources.Load("Textures/ShareToFacebook", typeof(Texture2D));
fbShareButton.renderer.material.mainTexture = tex0;
} else if (reward == 1) {
Texture2D tex1 = (Texture2D)Resources.Load("Textures/ShareToFacebook1", typeof(Texture2D));
fbShareButton.renderer.material.mainTexture = tex1;
} else if (reward == 3) {
Texture2D tex3 = (Texture2D)Resources.Load("Textures/ShareToFacebook3", typeof(Texture2D));
fbShareButton.renderer.material.mainTexture = tex3;
} else if (reward == 5) {
Texture2D tex5 = (Texture2D)Resources.Load("Textures/ShareToFacebook5", typeof(Texture2D));
fbShareButton.renderer.material.mainTexture = tex5;
}
Debug.Log ("Day: " + System.DateTime.Now.DayOfYear.ToString());
Debug.Log ("Reward: " + reward.ToString());
//enabled = false;
FB.Init(SetInit, OnHideUnity);
}
public static void Test ()
{
Debug.Log ("This is a test Press");
}
void OnGUI () {
}
private void SetInit()
{
//enabled = true; // "enabled" is a property inherited from MonoBehaviour
if (FB.IsLoggedIn) {
Debug.Log ("Logged into Facebook!!!!!!!!!!!!!!!!!!!");
} else {
Debug.Log ("Not logged in to FB D:");
//FBLogin ();
}
}
private void OnHideUnity(bool isGameShown)
{
if (!isGameShown)
{
// pause the game - we will need to hide
Time.timeScale = 0;
}
else
{
// start the game back up - we're getting focus again
Time.timeScale = 1;
}
}
void LoginCallback(FBResult result)
{
if (FB.IsLoggedIn)
{
Debug.Log ("Logged into Facebook!!!!!!!!!!!!!!!!!!!");
}
}
public static void PostToFB()
{
Debug.Log ("trying to post to facebook...");
FB.Feed(
link: "https://www.youtube.com/watch?v=bOD2-mRphTI",
linkName: "Relentless for Android",
linkCaption: "The Video is Un-related.",
linkDescription: "Relentless is a simplistic platform runner with randomly selected obstacles to avoid. A simple tapping game when you're looking to kill time. The further you get; the more obstacles are added to the mix! Customize your character with Skins, Trail Effect Colors, and New Jump sounds obtained by breaking a new distance records! Share your score to Facebook, and challenge your friends!",
picture: "https://dl.dropboxusercontent.com/u/17419144/Pictures/Screenshot_2015-04-12-21-59-30.png"
);
ResetButton();
//callback: LogCallback
}
public static void FBLogin ()
{
FB.Login ("user_birthday", AuthCallback);
}
public static void AuthCallback(FBResult result) {
if(FB.IsLoggedIn) {
Debug.Log("User is logged in as user ID: " + FB.UserId.ToString());
PostToFB();
} else {
Debug.Log("User cancelled login");
}
}
}
My Issue is, I can not run anything from “ResetButton” function for some reason because it says it is Non-Static, but as you can see it IS a static function. So what is wrong?? I am very frustrated.