Showing posts with label unity 5 tutorials. Show all posts
Showing posts with label unity 5 tutorials. Show all posts

Monday, 16 October 2017

Unity 2D Infinite Background Scrolling Simplest Way

Watch Video Tutorial
Code for Infinite Background Scrolling IN Unity 2d game.

using UnityEngine;
using System.Collections;
 
public class Scroll : MonoBehaviour
{
 
    public float backGroundSize;
 
    private Transform cameraTransform;
    public Transform[] layers;
 
    private float viewZone = 0;
    private int leftIndex;
    private int rightIndex;
 
    private void Start()
    {
        cameraTransform = Camera.main.transform;   
 
        leftIndex = 0;
        rightIndex = layers.Length - 1;
    }
 
    void Update()
    {
        if (cameraTransform.position.< 
            (layers[leftIndex].transform.position.+ viewZone))
            ScrollLeft();
 
        if (cameraTransform.position.> 
            (layers[rightIndex].transform.position.- viewZone))
            ScrollRight();
    }
 
    private void ScrollLeft()
    {    
        layers[rightIndex].position = new 
           Vector3
           (1f * (layers[leftIndex].position.- backGroundSize), 0f0f);
        leftIndex = rightIndex;
        rightIndex--;
        if (rightIndex < 0)
            rightIndex = layers.Length - 1;
    }
    private void ScrollRight()
    {   
        layers[leftIndex].position = 
            new Vector3
            (1f * (layers[leftIndex].position.+ backGroundSize), 0f10f);
        rightIndex = leftIndex;
        leftIndex++;
        if (leftIndex == layers.Length)
            leftIndex = 0;
    }
}

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 2D Camera Bounds

Watch Video Tutorial On Youtube


using UnityEngine;
using System.Collections;
 
public class CameraBounds : MonoBehaviour
{
 
    Vector3 screensize;
    public GameObject Right;
    public GameObject left;
    // Use this for initialization
 
 
    void Start()
    {
   screensize = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0));
 
    }
    // Update is called once per frame
    void Update()
    {
  screensize = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0));
  Right.transform.position = new Vector2(screensize.+ 0.65f0);
  left.transform.position = new Vector2((screensize.- 0.65f- 
   Camera.main.orthographicSize * Camera.main.aspect * 2f0);
    }
}

Sunday, 30 April 2017

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 [10]

Tutorial No. 10


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