(2024年2月24日)
・Unityを起動
・下記のようなエラーが表示されたら「Ignore」をクリックしましょう。
<スクリプトの修正>
・「PlayerMovement」スクリプトを開く
・42行目の最後に「セミコロン」を追加してコードチェック
・チェックが完了したらゲームを再生
(2024年2月17日)
<スクリプトの修正>
・PlayerMovemnetスクリプトを開く。
・赤枠の中の2行のコードを
*下記のように修正してください。(↓写真をクリックすると拡大画面で見ることができます)
チェックを入れて、ゲームを再生してみましょう。
空中でジャンプができなければ成功です。
(2024年2月10日)
<空中ジャンプの禁止>
・PlayerMovemnetスクリプトを開く
・下記「★★コードを追加」部分のコードを書いてチェック
・これだけでOKです。
・ゲームを再生して空中ではジャンプできないことを確認しましょう。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
    public float speed;
    private Animator animator;
    private SpriteRenderer spriteRenderer;
    public float jumpSpeed;
    public AudioClip jumpSound;
    private Rigidbody2D rb2d;
    private AudioSource audioSource;
    public LayerMask floor;
    void Start()
    {
        animator = GetComponent();
        spriteRenderer = GetComponent();
        rb2d = GetComponent();
        audioSource = GetComponent();
    }
    void Update()
    {
        float moveH = Input.GetAxisRaw("Horizontal");
        Vector2 movement = new Vector2(moveH, 0);
        transform.Translate(movement * Time.deltaTime * speed);
        animator.SetFloat("Speed", moveH);
        if (moveH > 0.5f)
        {
            spriteRenderer.flipX = false;
        }
        else if (moveH < -0.5f)
        {
            spriteRenderer.flipX = true;
        }
        // ★★コードの追加
        if (Input.GetKeyDown(KeyCode.Space) && IsGrounded()) // <・・・ここに「&& IsGrounded()」のコードを追加する。
        {
            rb2d.velocity = Vector2.up * jumpSpeed;
            audioSource.PlayOneShot(jumpSound);
            animator.SetTrigger("Jump");
        }
    }
    private bool IsGrounded()
    {
        RaycastHit2D hit2d = Physics2D.Raycast(transform.position, Vector2.down, 0.6f, floor);
        return hit2d.collider != null;
    }
}
    (2023年6月26日)
<敵の砲弾にあたるとゲームオーバーになる>
・Endスクリプトの改良
・下記のコードを書いてチェック
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using UnityEngine.SceneManagement;
public class end : MonoBehaviour
{
    private void OnControllerColliderHit(ControllerColliderHit hit)
    {
        if(hit.collider.CompareTag("Projectile"))
        {
            Invoke("GoToGameOver", 2.0f);
        }
    }
    void GoToGameOver()
    {
        // ゲームオーバーに移動する
        SceneManager.LoadScene("Menu Lose");
    }
}
<下に落ちたらゲームオーバーになる>
・「Fall」スクリプトの改良
・下記のコードを書いてチェック
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using UnityEngine.SceneManagement;
public class Fall : MonoBehaviour
{
    void Update()
    {
        Vector3 pos = transform.position;
        if(pos.y < -50)
        {
            SceneManager.LoadScene("Menu Lose");
        }
    }
}
(2023年4月1日のフィードバック)
最初にスクリプトを書きましょう!
・MoveDoorスクリプトをダブルクリック
・下記のコードを書いてチェック
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveDoor : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(MoveUp());
    }
    private IEnumerator MoveUp()
    {
        while (true)
        {
            Vector3 pos = transform.position;
            // 上に移動させる。
            transform.Translate(0, 0.01f, 0);
            yield return new WaitForSeconds(0.01f);
            // どの高さで止めるかは自分の世界に合わせて設定
            if (pos.y > 12.5f)
            {
                break;
            }
        }
    }
}
・コードチェックができたら、紫色の扉にスクリプトを追加しましょう!
・設定ができたらゲームを再生!
・扉が上方向に動いたら成功です。







