Showing posts with label Game development. Show all posts
Showing posts with label Game development. Show all posts

Thursday, 17 May 2018

how to use slider in unity


first goto -> create -> UI -> slider and create a slider this will create a canvas if not already created.
create a script and attach it to any gameobject (payer or camera) or just put the code in any script
assing the public slider variable in inspector by draging the slider component from hierarchy to inspector as shown below.

now run the code after running you will notice the slider value will change to 10 as written in code.

Friday, 20 October 2017

Unity AdMob (Google Mobile Ads ) Unity Plugin Integration


---- Watch Video Tutorials ----
Admob Integration Tutorial :
https://youtu.be/8wGXcEOYOig
-------------------------------
How To Fix AdMob Problem
https://youtu.be/JRGd7UG-WdE
------------------------------

using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
using System;
 
public class AdManager : MonoBehaviour
{
 
    //THE SCRIPT HAS ORIGNAL ID'S OF ADMOB
    InterstitialAd interstitial;
    BannerView bannerView;
    // Use this for initialization
    void Start()
    {
 
        RequestBanner();
        RequestInterstitial();
    }
 
 
    public void RequestBanner()
    {
   // replace this id with your orignal admob id for banner ad
        string adUnitId = "ca-app-pub-3940256099942544/6300978111";
 
        // Create a 320x50 banner at the top of the screen.
        bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);
        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();
        // Load the banner with the request.
        bannerView.LoadAd(request);
        bannerView.OnAdLoaded += HandleOnAdLoaded;
 
    }
 
    void HandleOnAdLoaded(object a, EventArgs args)
    {
        print("loaded");
        bannerView.Show();
    }
 
 
    public void RequestInterstitial()
    {
 
        string adUnitId = "your interstial ad id here";
 
 
        // Initialize an InterstitialAd.
        interstitial = new InterstitialAd(adUnitId);
        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();
        // Load the interstitial with the request.
        interstitial.LoadAd(request);
 
 
    }
 
    public void show()
    {
        if (interstitial.IsLoaded())
        {
            interstitial.Show();
        }
    }
 
 
}

Sunday, 15 October 2017

The Best Way to jump in Unity3d

Attach these two scripts with your player  and feel the difference in jumping it works both for 3D and 2D for 2D you have to make some adjustments in betterJump script.

WATCH VIDEO TUTORIAL

Player Script:


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour {
    public float speed = 10.0F;
    public float rotationSpeed = 100.0F;
    // Use this for initialization
    void Start () {
  
 }
 
 // Update is called once per frame
 void Update () {
 
        float translation = Input.GetAxis("Vertical"* speed;
        float rotation = Input.GetAxis("Horizontal"* rotationSpeed;
 
        translation *= Time.deltaTime;
        rotation *= Time.deltaTime;
 
        transform.Translate(00, translation);
        transform.Rotate(0, rotation, 0);
 
        if (Input.GetKeyDown(KeyCode.Space))
        {
            jump();
        }
    }
    void jump()
    {
        transform.GetComponent<Rigidbody>().AddForce(new Vector3(0190 * Time.deltaTime, 0),ForceMode.Impulse);
    }
}



Better Jump Script (for 3D project)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class fastJump : MonoBehaviour {
 
    public float fallMultiplier = 2.5f;
    public float lowJumpMultiplier = 2f;
    Rigidbody rb;
 
 
    void Awake()
    {
        rb = GetComponent<Rigidbody>();
    }
    void Update()
    {
        if (rb.velocity.< 0)
        {
            rb.velocity += Vector3.up * Physics.gravity.* (fallMultiplier - 1)
 * Time.deltaTime;
        }
    }
}

Better Jump Script (for 2D project)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class fastJump : MonoBehaviour {
    public float fallMultiplier = 2.5f;
    public float lowJumpMultiplier = 2f;
    Rigidbody2D rb;
    void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
    }
    void Update()
    {
        if (rb.velocity.< 0)
        {
            rb.velocity += Vector2.up * Physics2D.gravity.*
                (fallMultiplier - 1* Time.deltaTime;
        }
    }
 
 
}

Friday, 13 October 2017

Unity Universal Share Link Button Code for Android And IOS

Watch Video On YouTube


using UnityEngine;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
 
 
public class ShareAndRate : MonoBehaviour {
 
 string subject = "Aim n Shoot";
 string body = "https://play.google.com/store/apps/details?id=com.webroid.smashy.cat.kitty";
 
 #if UNITY_IPHONE
 
 [DllImport("__Internal")]
 private static extern void sampleMethod (string iosPath, string message);
 
 [DllImport("__Internal")]
 private static extern void sampleTextMethod (string message);
 
 #endif
 
 public void OnAndroidTextSharingClick()
 {
  
  StartCoroutine(ShareAndroidText());
  
 }
 IEnumerator ShareAndroidText()
 {
  yield return new WaitForEndOfFrame();
  //execute the below lines if being run on a Android device
  #if UNITY_ANDROID
  //Reference of AndroidJavaClass class for intent
  AndroidJavaClass intentClass = new AndroidJavaClass ("android.content.Intent");
  //Reference of AndroidJavaObject class for intent
  AndroidJavaObject intentObject = new AndroidJavaObject ("android.content.Intent");
  //call setAction method of the Intent object created
  intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
  //set the type of sharing that is happening
  intentObject.Call<AndroidJavaObject>("setType""text/plain");
  //add data to be passed to the other activity i.e., the data to be sent
  intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), subject);
  //intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TITLE"), "Text Sharing ");
  intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), body);
  //get the current activity
  AndroidJavaClass unity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
  AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
  //start the activity by sending the intent data
  AndroidJavaObject jChooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intentObject, "Share Via");
  currentActivity.Call("startActivity", jChooser);
  #endif
 }
 
 
 public void OniOSTextSharingClick()
 {
  
  #if UNITY_IPHONE || UNITY_IPAD
  string shareMessage = "Wow I Just Share Text ";
  sampleTextMethod (shareMessage);
  
  #endif
 }
 
 public void RateUs()
 {
  #if UNITY_ANDROID
  Application.OpenURL("market://details?id=YOUR_ID");
  #elif UNITY_IPHONE
  Application.OpenURL("itms-apps://itunes.apple.com/app/idYOUR_ID");
  #endif
 }
 
}

Sunday, 30 April 2017

Unity3D Tutorial in Urdu / Hindi [14]

Tutorial No. 14


Welcome to unity 3_D video tutorial series in Urdu .

(1) Duration Of Course : 90 MINUTES
(2)Level : Beginners
(3)Total videos :14

These tutorials are created with Unity personnel edition V 5.3.5



Unity3D Tutorial in Urdu / Hindi [13]

Tutorial No. 13


Welcome to unity 3_D video tutorial series in Urdu .

(1) Duration Of Course : 90 MINUTES
(2)Level : Beginners
(3)Total videos :14

These tutorials are created with Unity personnel edition V 5.3.5



Unity3D Tutorial in Urdu / Hindi [12]

Tutorial No. 12


Welcome to unity 3_D video tutorial series in Urdu .

(1) Duration Of Course : 90 MINUTES
(2)Level : Beginners
(3)Total videos :14

These tutorials are created with Unity personnel edition V 5.3.5



Unity3D Tutorial in Urdu / Hindi [11]

Tutorial No. 11


Welcome to unity 3_D video tutorial series in Urdu .

(1) Duration Of Course : 90 MINUTES
(2)Level : Beginners
(3)Total videos :14

These tutorials are created with Unity personnel edition V 5.3.5



Unity3D Tutorial in Urdu / Hindi [09]

Tutorial No. 9


Welcome to unity 3_D video tutorial series in Urdu .

(1) Duration Of Course : 90 MINUTES
(2)Level : Beginners
(3)Total videos :14

These tutorials are created with Unity personnel edition V 5.3.5



Unity3D Tutorial in Urdu / Hindi [08]

Tutorial No. 8


Welcome to unity 3_D video tutorial series in Urdu .

(1) Duration Of Course : 90 MINUTES
(2)Level : Beginners
(3)Total videos :14

These tutorials are created with Unity personnel edition V 5.3.5



Unity3D Tutorial in Urdu / Hindi [07]

Tutorial No. 7


Welcome to unity 3_D video tutorial series in Urdu .

(1) Duration Of Course : 90 MINUTES
(2)Level : Beginners
(3)Total videos :14

These tutorials are created with Unity personnel edition V 5.3.5



Unity3D Tutorial in Urdu / Hindi [06]

Tutorial No. 6


Welcome to unity 3_D video tutorial series in Urdu .

(1) Duration Of Course : 90 MINUTES
(2)Level : Beginners
(3)Total videos :14

These tutorials are created with Unity personnel edition V 5.3.5



Unity3D Tutorial in Urdu / Hindi [05]

Tutorial No. 5


Welcome to unity 3_D video tutorial series in Urdu .

(1) Duration Of Course : 90 MINUTES
(2)Level : Beginners
(3)Total videos :14

These tutorials are created with Unity personnel edition V 5.3.5.

Unity Tutorial in Urdu / Hindi [04]

Tutorial No.4

Welcome to unity 3_D video tutorial series in Urdu .

(1) Duration Of Course : 90 MINUTES
(2)Level : Beginners
(3)Total videos :14
these tutorials are created with Unity3d personel edition V 5.3.5