adssencee

Monday, May 4, 2020

How to setup unity 2d Game Development Android Button ?

How to setup unity 2d Game Development  Android Button? 

Hello, friends this me gour. so you look Above the Heading. How to setup unity 2d Game Development 

Android Button.a friend I tell you how to set up button first, create your project.
 unity 2d game development first creates your project. then go to your File and bulid Setting and select

your Android plateform swich platform. unity 2d game development engine all you project convert

Android plateform.After that you go go to Asset store download the StanderAsset And Import your

unity 2d game development engine.After that friends you Hirachay panel right Mouse click and create your

UI Button.





After that friends go to your canvas Selected & Render Mode screen Space-camera. or Selected Render camera to MainCamera.

Now Friends go to your unity 2d game Button Seleted And you see Target graphice .Here are you selected  your Sprite Button Image.  After that go to your Stander Asset folder dueble click And open it you look croseplateformInpute Open it. Then you See Scripts Floder

duble click Open it. Then you see All Scripts now you selected One Scripts name it AxiesTouchButton drag it the button . Now you see Button under Script button name leftbutton. Then Ctl+C and copy it.

Ctrl+V  past it. secendButton Name RightButton.Here are I am past the playerContrloller Scripts. After that Right button selected copy And past  and name it jumpButton. you see jumpbutton Script Axiestouchbutton

remove. and go to your Scripts folders ButtonHandlear Scripts drag your JumpButton. After that JumpButton Seleceted copy and past this Button name it AttackButton.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;  // friends this Must bee one this varivale Importent.
public class playercontrole : MonoBehaviour
{
    private Rigidbody2D playerrb;
    public float speed;
    public float jump;
    public bool islookleft;
    private Animator anim;
    private bool isground;
    public Transform isgroud;


    // Use this for initialization
    void Start()
    {
        playerrb = GetComponent<Rigidbody2D>();
        anim = GetComponent<Animator>();


    }

    // Update is called once per frame
    void Update()
    {

        Movement();
        fixupdate();



    }

    void Movement()
    {
        float h = CrossPlatformInputManager.GetAxisRaw("Horizontal");  // This  your button left And right button input
        playerrb.velocity = new Vector2(h * speed, playerrb.velocity.y);     //This Horizontal name And button scripts name same it if you not  same you it your button not work
        anim.SetInteger("speed", (int)h);
        anim.SetBool("isground", isground);
        anim.SetFloat("Blend", playerrb.velocity.y);


        if (h > 0 && islookleft == true)
        {
            Flip();
        }
        else if (h < 0 && islookleft == false)
        {
            Flip();
        }
        if (CrossPlatformInputManager.GetButtonDown("Attack")) // This your Attack button

        {
            anim.SetTrigger("Attack");
        }

        if (CrossPlatformInputManager.GetButtonDown("Jump") && isground == true) // This your jump button
        {
            playerrb.AddForce(new Vector3(0, jump));

        }

    }
    void Flip()
    {
        islookleft = !islookleft;
        float x = transform.localScale.x * -1;
        transform.localScale = new Vector3(x, transform.localScale.y, transform.localScale.z);

    }

    void fixupdate()
    {
        isground = Physics2D.OverlapCircle(isgroud.position, 0.02f);
    }
}
 



now All button Scripts funsantan Seleceted:-

look look ths Image


This Image AxiestouchButton scripts Axes name Horizontal.  Axes value -1. why -1 value use . It use that your rigid charater move left side And rightButton not -1 just like Image. LeftButton After that Response

Speed 1000 or Right button Response speed same1000 After that you play you game you see it working your left And right button. now set the JumpButton go to you button HandelerSecripts you look funcane

Name - Jump. this name Scripts name same it . you do not use same name your JumpButton  not work




on click() look you  you don't see the funcation plaese click + sine noneObject seleted your jump button.Now you see no function selected you buttonHandeler and seleceted  SetupState()  After that + sine click

noneObject seleted your jump button.Now you see no function selected you buttonHandeler and seleceted  SetdownState()  Same function for use Attack button
. but name your Attack. player controller Scripts

you don't under stand plaese look my video this my you tube channel dbz shiva














so friends visit my youtube Channel see my all unity 2d game development. or subscribe my youtbe channel. pleasse any problem plasee comment.



thanks.


































































No comments:

Post a Comment

Please do not Enter any Spam link in the Comment Box