ポケモン

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

public class PlayerController : MonoBehaviour
{
public float moveSpeed;
public LayerMask solidObjectsLayer;
public LayerMask grassLayer;

private bool isMoving;
private Vector2 input;

private Animator animator;

private void Awake()
{
    animator = GetComponent<Animator>();
}
private void Update()
{
       if (!isMoving)
        {
        input.x = Input.GetAxisRaw("Horizontal");
        input.y = Input.GetAxisRaw("Vertical");

        //remove diagonal movement
        if (input.x != 0) input.y = 0;

        if(input != Vector2.zero)
        {
            animator.SetFloat("moveX", input.x);
            animator.SetFloat("moveY", input.y);
            var targetPos = transform.position;
            targetPos.x += input.x;
            targetPos.y += input.y;

            if(IsWalkable(targetPos))
            StartCoroutine(Move(targetPos));
        }
    }

    animator.SetBool("isMoving", isMoving);
}
IEnumerator Move(Vector3 targetPos)
{
    isMoving = true;

    while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
    {
        transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
        yield return null;
    }
    transform.position = targetPos; // 目標位置に合わせて最終位置を設定

    isMoving = false;

    CheckForEncounters();
}

private bool IsWalkable(Vector3 tagetPos)
{
    if(Physics2D.OverlapCircle(tagetPos, 0.2f, solidObjectsLayer) != null)
    {
        return false;
    }

    return true;
}

private void CheckForEncounters()
{
    if(Physics2D.OverlapCircle(transform.position, 0.2f, grassLayer) != null)
    {
        if(Random.Range(1, 101) <= 10)
        {
            Debug.Log("野生のポケモンに遭遇した");
        }
   
}

}

PlayerController.cs

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

[CreateAssetMenu(fileName = “ポケモン”, menuName = “ポケモン/新しいポケモンを作成する”)]
public class PokemonBase : ScriptableObject
{
[SerializeField] string name;

[TextArea]
[SerializeField] string description;

[SerializeField] Sprite frontSprite;
[SerializeField] Sprite backSprite;

[SerializeField] PokemonType type1;
[SerializeField] PokemonType type2;

//Base Stats
[SerializeField] int maxHp;
[SerializeField] int attack;
[SerializeField] int defense;
[SerializeField] int spAttack;
[SerializeField] int spDefense;
[SerializeField] int speed;

}

public enum PokemonType
{
None,
Normal,
Fire,
Water,
Electric,
Grass,
Ice,
Fighting,
Poison,
Ground,
Flying,
Psychic,
Bug,
Rock,
Ghost,
Dragon
}

PokemonBase

投稿者: chosuke

趣味はゲームやアニメや漫画などです

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です