start timer was not working in unity

0 votes

i am getting compile error when i try to use timer script

using UnityEngine;
using System.Collections;
using com.shephertz.app42.paas.sdk.csharp;
using com.shephertz.app42.paas.sdk.csharp.timer;



	public class Unitycallback : App42CallBack 

{
	
	
	string timername = "demo";
	string userName = "demo";
	App42Log.SetDebug (true);
	App42API.Initialize("API_KEY","SECRET_KEY");  
	TimerService timerService =  App42API.BuildTimerService();  
	timerService.StartTimer(timerName, userName, new UnityCallBack());   

	{  
		public void OnSuccess(object response)  
		{  
			Timer timer = (Timer)response;  
			App42Log.Console("Timer Name is: "+timer.GetName());  
			App42Log.Console("UserName is:" + timer.GetUserName());  
			App42Log.Console("Current time is:" + timer.GetCurrentTime());  
			App42Log.Console("Start time is:" + timer.GetStartTime());  
			App42Log.Console("End time is:" + timer.GetEndTime());  
		}  
		public void OnException(Exception e)  
		{  
			App42Log.Console("Exception : " + e);  
		}  
	}  

 

asked Mar 29, 2016 in Unity by corei5unity (11 points)

1 Answer

0 votes

Hi Core,

You can simply do the same in your main Scence by defining a function startTimer can call the same from where you want to call like on some button click.

You can refer more Unity Sample available on Git Hub. I am also sharing sample source code how you implement the same.
 

    using UnityEngine;
    using System.Collections;
    using com.shephertz.app42.paas.sdk.csharp;
    using com.shephertz.app42.paas.sdk.csharp.timer;
    public class UnitySample : MonoBehaviour, App42CallBack
    {
        void Start ()
        {
         string timername = "demo";
        string userName = "demo";
        App42Log.SetDebug (true);
        App42API.Initialize("API_KEY","SECRET_KEY");  
        }
        
        void OnGUI ()
        {
        //UI Creation code
        }
        
        //Start timer by calling this method
        void startTimer(){
         TimerService timerService =  App42API.BuildTimerService();  
        timerService.StartTimer(timerName, userName, new UnityCallBack());
        }
        //Success Callback
        public void OnSuccess(object response)  
            {  
                Timer timer = (Timer)response;  
                App42Log.Console("Timer Name is: "+timer.GetName());  
                App42Log.Console("UserName is:" + timer.GetUserName());  
                App42Log.Console("Current time is:" + timer.GetCurrentTime());  
                App42Log.Console("Start time is:" + timer.GetStartTime());  
                App42Log.Console("End time is:" + timer.GetEndTime());  
            }  
            //Exception Callback
        public void OnException(Exception e)  
            {  
                App42Log.Console("Exception : " + e);  
            }
    }

Let me know if more queries are concern.

Thanks

Vishnu Garg

answered Mar 30, 2016 by Vishnu Garg (674 points)
edited Mar 30, 2016 by Vishnu Garg
Assets/scripts/time.cs(36,33): error CS0246: The type or namespace name `Exception' could not be found. Are you missing a using directive or an assembly reference?
i get error when i use this code
Add namespace using System;
Also change the line
timerService.StartTimer("demo", "demo",this);
also i like to know
in the dashboard timer do not have username filed so will it be handled in background like attaching the timer to username we give in code ?
if it was not pls explain
Yes, You can send the user name that you have set using App42API.setLoogedinUSer API
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...