Skip to main content

Posts

Showing posts from August, 2014

How to show Admob ads in Center of the screen in unity Iphone

Hi Guys If anyone want can use this solution to show Admob ads in center of the screen, I used Google Official Admob plugin. You can find a very nice video here link which describe how to setup everything in xcode. I am giving a link to my project file below, you can directly build and test it on any iphone or ipad devices.

So what i did ?

I added another value to enum in AdPosition.cs (Center), adding (Center) in AdPosition is not enough, i had to change in native code also, so i made few changes in GADUBanner.h and GADUBanner.m .



In GADUBanner.h i added another value to the enum, that is kGADAdPositionCenterOfScreen = 2



And in GADUBanner.m i made few changes in the switch statement which set the Center of the ad badder.

- (void)adViewDidReceiveAd:(GADBannerView *)adView  {
  UIView *unityView = [[GADUBanner unityGLViewController] view];   CGPoint center = CGPointMake(CGRectGetMidX(unityView.bounds), CGRectGetMidY(_bannerView.bounds)); // Position the GADBannerView. switch (self.adPositi…

How to make CountDown timer in unity

Hi, this post is just for my own collection of useful stuffs, I found the Js version of this Timer script in unity forums, Added reset function and wrote a c sharp version.


C# (C-Sharp)
usingUnityEngine;
usingSystem.Collections;

publicclassTimerCS : MonoBehaviour {


privatefloatstartTime;
privateintrestSeconds;
privateintroundedRestSeconds;
privateintdisplaySeconds;
privateintdisplayMinutes;
privatestringtext;

publicintcountDownSeconds = 45;   //inseconds

voidAwake()
    {
startTime = Time.time;
    }

voidUpdate () {


floatguiTime = Time.time - startTime;

restSeconds = (int)(countDownSeconds - (guiTime));

//displaythetimer
roundedRestSeconds = Mathf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
displayMinutes = roundedRestSeconds / 60; 

text = string.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds);



    }

voidOnGUI()
    {
GUI.skin.box.fontStyle = FontStyle.Bold;
GUI

How to get precise Input value from Accelerometer in unity

Hi guys, today i am going to show you how you can get a precise input from accelerometer.
Usually if you have visualise accelerometer Input in unity than you might have seen something like these 0.123765 or like these 0.5874938,  And getting a perfect 0 is almost impossible, either its Iphone or Android both are same.
So it was on my head for a long time, how to solve this issue, and finally i found a simple solution which works like a charm.

You just need to write 2 lines of code.


doubleaccx     = Input.acceleration.x;
floatGetAxisH = (float)System.Math.Round(accx,1);


First you need to take the Input.acceleration.x in a double variable than Round it to 1 decimal place and than cast it to a float type and use the GetAxisH as your horizontal input. With this method you also get a perfect 0 as your acceleration Input, according to my tests you get value like these 0,0.1,0.2 or these 0,-0.1,-0.2........

Ask me if you have any questions related to this post.

thanks
Sushanta