Hello, Friends This me Gour Hari Ghosh. Here is this Content Abobe see you Heading. I Told you
easy way setup Camera unity 2d Game development. if you learn other Setup for a unity game.
Please see the Other Content. unity Camera Setup so Easy friends. First, you learn to code. Friends C# language.
you see the unity C# coding And Create your unity 2d Game. But don't learn unity C# Coding
Remember your not a good game developer for the Unity Engine. because of A good game
developer's fist understands theUnity C# coding After that Create your Unity 2d games.
Here Above See the unity 2d game Image, I am creating a unity 2d game. how to create unity 2d
game Camera setting. let's talk all Details
Friends first unity 2d game engine complete your project unity 2d character setup After that
create unity 2d game engine GameControler Script Assets just like Above the Image. And 2d unity
Engine Hierarchy
Right, Mouse clicks and createempty you see the GameObject. This unity 2d GameObject right Mouse click
rename it GameControler. now drag your scrip to you GameControler GameObject. Now you unity
2d game
See GameObject Gamecontrler transform position All X, Y, Z value set 0 shows the Images
unity 2d game engine Asset Duble click GameController Script Open it you coding Editor Just
like Mono developer or visual studio. you see the coding all complete Gamecontroler Script
you see it
unity 2d Gamecontrler Scripts
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gamecontrler : MonoBehaviour {
public Transform playertranform,camEsc,camDir,camSub,cambas; // This your unity 2d GameCotroler
Objcet tranansform all.
private Camera cm; // This your unity 2d camera varibale
public float camspeeed; // This your unity 2d cherater camera speed varivale
// Use this for initialization
void Start () {
cm = Camera.main; // here Are set Your unity 2d camer for Start
}
// Update is called once per frame
void Update () {
}
void LateUpdate()
{
float poscamX = playertranform.position.x; // here unity 2d player tranform posin varible
float poscamY = playertranform.position.y;
if(cm.transform.position.x <camEsc.transform.position.x && poscamX < camEsc.transform.position.x)
{
poscamX = camEsc.transform.position.x;
}
else if (cm.transform.position.x > camDir.transform.position.x && poscamX > camDir.transform.position.x)
{
poscamX = camDir.transform.position.x;
}
if (cm.transform.position.y < cambas.transform.position.y && poscamY < cambas.transform.position.y)
{
poscamY = cambas.transform.position.y;
}
else if (cm.transform.position.y > camSub.transform.position.y && poscamY > camSub.transform.position.y)
{
poscamY = camSub.transform.position.y;
}
Vector3 poscam = new Vector3(poscamX, poscamY, cm.transform.position.z);
cm.transform.position = Vector3.Lerp(cm.transform.position, poscam, camspeeed * Time.deltaTime);
}
}
This unity C# coding You copy it and past Your unity 2d game controller Scripts, it's Working. here are double // the
comment on coding. but unity 2d player controller Scripts some setting I past it. you see the double//
this your unity 2d gameconroler Scripts setting
player controller coding.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class playercontroller : MonoBehaviour {
private gamecontrler _Gamecontrler;// this your unity 2d cmera controller varivle.
private Rigidbody2D playerb;
public float speed, jumpforcw;
public bool isloookleft;
private Animator playerAnimator;
public Transform groundchek;
private bool isGrounded;
private bool isAtttack;
public GameObject prefabhitbox;
public Transform mao;
// Use this for initialization
void Start () {
playerb = GetComponent<Rigidbody2D>();
playerAnimator = GetComponent<Animator>();
_Gamecontrler = FindObjectOfType(typeof(gamecontrler)) as gamecontrler; //this your unity 2d obejct gamecontroller setting.
_Gamecontrler.playertranform = this.transform; // this your unty 2d chereater setting.
}
// Update is called once per frame
void Update () {
Movement();
FixedUpdated();
}
void Movement()
{
float h = CrossPlatformInputManager.GetAxis("Horizontal");
playerb.velocity = new Vector2(h * speed, playerb.velocity.y);
if (
isAtttack == true && isGrounded==true
)
{
h = 0;
}
if (h>0 && isloookleft == true)
{
Flip();
}
else if(h<0&& isloookleft == false)
{
Flip();
}
if (CrossPlatformInputManager.GetButtonDown("Jump")&& isGrounded== true)
{
playerb.AddForce(new Vector2(0, jumpforcw));
}
if (CrossPlatformInputManager.GetButtonDown("Attack")&& isAtttack==false)
{
isAtttack = true;
playerAnimator.SetTrigger("Attack");
}
playerAnimator.SetInteger("speed", (int) h);
playerAnimator.SetBool("isGrounded", isGrounded);
playerAnimator.SetFloat("speedy", playerb.velocity.y);
playerAnimator.SetBool("isAttack", isAtttack);
}
void FixedUpdated()
{
isGrounded = Physics2D.OverlapCircle(groundchek.position,0.02f);
}
void Flip()
{
isloookleft = !isloookleft;
float x = transform.localScale.x * -1;
transform.localScale = new Vector3(x, transform.localScale.y, transform.localScale.z);
}
void EndAttack()
{
isAtttack = false;
}
void HitboxAttack()
{
GameObject hitboxtemp = Instantiate(prefabhitbox, mao.position, transform.localRotation);
Destroy(hitboxtemp, 0.2f);
}
}
unity 2d coding you Complete After that go to your unity 2d game engine Gamecontroler Object below
unity 2d create Game empty and name it camesc, copy it And three time past it And re name it camdir,
camsub, cambas All z transform -10 see bnelow Image
you Look Image And the same to you do it. you play unity 2d game you look you camera move
properly.
mow Expleane you're All camera direction Remember I told you here are fourth camera diration
fast camera direction camesc :- what is camesc diration ?
camesc your player diration. camesc GameObeject selected And unity Move Toll drag Any whare
camera poison begin it fast.
second camera direction camdir :-what is camdir diration ?
camdir diration are not moveing the camera. camdir GameOjet selected And unity Move toll drag
Anywhere and you play game character go to your camdir gameObject drag position this time
camera Movement not work.
Third camera direction camsub :-what is camsub diration ?
camsub diration are not moveing the camera. camsub GameOjet selected And unity Move toll drag
up the playerCherater and you play game character go to jump your camsub gameObject drag
position this time camera Movement not work.
Fourth camera direction cambas :-what is cambas diration ?
cambase diraction is the Main camera diraction you selected cambase gameObject And Main
camera All position copy And cambas gameObject transform past value After that you play
unity 2d game And position your MainCamera set.
So friends you Any problem please visit my youtube channel dbz shiva and see the video
please comment below the box.
easy way setup Camera unity 2d Game development. if you learn other Setup for a unity game.
Please see the Other Content. unity Camera Setup so Easy friends. First, you learn to code. Friends C# language.
you see the unity C# coding And Create your unity 2d Game. But don't learn unity C# Coding
Remember your not a good game developer for the Unity Engine. because of A good game
developer's fist understands theUnity C# coding After that Create your Unity 2d games.
Here Above See the unity 2d game Image, I am creating a unity 2d game. how to create unity 2d
game Camera setting. let's talk all Details
Friends first unity 2d game engine complete your project unity 2d character setup After that
create unity 2d game engine GameControler Script Assets just like Above the Image. And 2d unity
Engine Hierarchy
Right, Mouse clicks and createempty you see the GameObject. This unity 2d GameObject right Mouse click
rename it GameControler. now drag your scrip to you GameControler GameObject. Now you unity
2d game
See GameObject Gamecontrler transform position All X, Y, Z value set 0 shows the Images
unity 2d game engine Asset Duble click GameController Script Open it you coding Editor Just
like Mono developer or visual studio. you see the coding all complete Gamecontroler Script
you see it
unity 2d Gamecontrler Scripts
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gamecontrler : MonoBehaviour {
public Transform playertranform,camEsc,camDir,camSub,cambas; // This your unity 2d GameCotroler
Objcet tranansform all.
private Camera cm; // This your unity 2d camera varibale
public float camspeeed; // This your unity 2d cherater camera speed varivale
// Use this for initialization
void Start () {
cm = Camera.main; // here Are set Your unity 2d camer for Start
}
// Update is called once per frame
void Update () {
}
void LateUpdate()
{
float poscamX = playertranform.position.x; // here unity 2d player tranform posin varible
float poscamY = playertranform.position.y;
if(cm.transform.position.x <camEsc.transform.position.x && poscamX < camEsc.transform.position.x)
{
poscamX = camEsc.transform.position.x;
}
else if (cm.transform.position.x > camDir.transform.position.x && poscamX > camDir.transform.position.x)
{
poscamX = camDir.transform.position.x;
}
if (cm.transform.position.y < cambas.transform.position.y && poscamY < cambas.transform.position.y)
{
poscamY = cambas.transform.position.y;
}
else if (cm.transform.position.y > camSub.transform.position.y && poscamY > camSub.transform.position.y)
{
poscamY = camSub.transform.position.y;
}
Vector3 poscam = new Vector3(poscamX, poscamY, cm.transform.position.z);
cm.transform.position = Vector3.Lerp(cm.transform.position, poscam, camspeeed * Time.deltaTime);
}
}
This unity C# coding You copy it and past Your unity 2d game controller Scripts, it's Working. here are double // the
comment on coding. but unity 2d player controller Scripts some setting I past it. you see the double//
this your unity 2d gameconroler Scripts setting
player controller coding.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class playercontroller : MonoBehaviour {
private gamecontrler _Gamecontrler;// this your unity 2d cmera controller varivle.
private Rigidbody2D playerb;
public float speed, jumpforcw;
public bool isloookleft;
private Animator playerAnimator;
public Transform groundchek;
private bool isGrounded;
private bool isAtttack;
public GameObject prefabhitbox;
public Transform mao;
// Use this for initialization
void Start () {
playerb = GetComponent<Rigidbody2D>();
playerAnimator = GetComponent<Animator>();
_Gamecontrler = FindObjectOfType(typeof(gamecontrler)) as gamecontrler; //this your unity 2d obejct gamecontroller setting.
_Gamecontrler.playertranform = this.transform; // this your unty 2d chereater setting.
}
// Update is called once per frame
void Update () {
Movement();
FixedUpdated();
}
void Movement()
{
float h = CrossPlatformInputManager.GetAxis("Horizontal");
playerb.velocity = new Vector2(h * speed, playerb.velocity.y);
if (
isAtttack == true && isGrounded==true
)
{
h = 0;
}
if (h>0 && isloookleft == true)
{
Flip();
}
else if(h<0&& isloookleft == false)
{
Flip();
}
if (CrossPlatformInputManager.GetButtonDown("Jump")&& isGrounded== true)
{
playerb.AddForce(new Vector2(0, jumpforcw));
}
if (CrossPlatformInputManager.GetButtonDown("Attack")&& isAtttack==false)
{
isAtttack = true;
playerAnimator.SetTrigger("Attack");
}
playerAnimator.SetInteger("speed", (int) h);
playerAnimator.SetBool("isGrounded", isGrounded);
playerAnimator.SetFloat("speedy", playerb.velocity.y);
playerAnimator.SetBool("isAttack", isAtttack);
}
void FixedUpdated()
{
isGrounded = Physics2D.OverlapCircle(groundchek.position,0.02f);
}
void Flip()
{
isloookleft = !isloookleft;
float x = transform.localScale.x * -1;
transform.localScale = new Vector3(x, transform.localScale.y, transform.localScale.z);
}
void EndAttack()
{
isAtttack = false;
}
void HitboxAttack()
{
GameObject hitboxtemp = Instantiate(prefabhitbox, mao.position, transform.localRotation);
Destroy(hitboxtemp, 0.2f);
}
}
unity 2d coding you Complete After that go to your unity 2d game engine Gamecontroler Object below
unity 2d create Game empty and name it camesc, copy it And three time past it And re name it camdir,
camsub, cambas All z transform -10 see bnelow Image
you Look Image And the same to you do it. you play unity 2d game you look you camera move
properly.
mow Expleane you're All camera direction Remember I told you here are fourth camera diration
fast camera direction camesc :- what is camesc diration ?
camesc your player diration. camesc GameObeject selected And unity Move Toll drag Any whare
camera poison begin it fast.
second camera direction camdir :-what is camdir diration ?
camdir diration are not moveing the camera. camdir GameOjet selected And unity Move toll drag
Anywhere and you play game character go to your camdir gameObject drag position this time
camera Movement not work.
Third camera direction camsub :-what is camsub diration ?
camsub diration are not moveing the camera. camsub GameOjet selected And unity Move toll drag
up the playerCherater and you play game character go to jump your camsub gameObject drag
position this time camera Movement not work.
Fourth camera direction cambas :-what is cambas diration ?
cambase diraction is the Main camera diraction you selected cambase gameObject And Main
camera All position copy And cambas gameObject transform past value After that you play
unity 2d game And position your MainCamera set.
So friends you Any problem please visit my youtube channel dbz shiva and see the video
please comment below the box.
No comments:
Post a Comment
Please do not Enter any Spam link in the Comment Box