UnityGame②格闘ゲーム#1

ゲームを作る。
  • ###0 プロジェクト作成
  • ###1 ステージ作成
  • ###2 キャラクター配置
  • ###3 当たり判定をつけて地面に立たせる

プロジェクト作成


1,2D:名前
2,Asset Storeに行く
--Window > Asset Store
Demoが入っている

ステージ作成

キャラクター配置
当たり判定

記事の細かいことは後述。
完成品は下記に。

### キャラクターの移動
### 敵の配置



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

public class PlayerManager : MonoBehaviour
{
    public float moveSpeed = 3;
    Animator animator;
    Rigidbody2D rb;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        animator = GetComponent<Animator>();
    }

    void Update()
    {
        float x = Input.GetAxisRaw("Horizontal");
        //Debug.Log(x);
        if(x > 0)
        {
            transform.localScale = new Vector3(-1, 1, 1);
        }
        if (x < 0)
        {
            transform.localScale = new Vector3(1, 1, 1);
        }
        animator.SetFloat("Speed", Mathf.Abs(x));
        rb.velocity = new Vector2(x*moveSpeed, rb.velocity.y);
    }
}

Next Post Previous Post
No Comment
Add Comment
comment url