制作RPG游戏的部分核心代码分析

本文将深入探讨Unity引擎中制作RPG游戏的关键部分,包括PlayerMove脚本的实现,解决PlayerDir玩家朝向问题,以及PlayerAnimation脚本的设计。同时,还会讲解相机跟随的脚本技术,为游戏带来流畅的视觉体验。
摘要由CSDN通过智能技术生成

PlayerMove脚本

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

public enum State
{
   
    Idle,
    Walk
}


public class PlayerMove : MonoBehaviour
{
   
    public float speed = 1;
    private PlayerDir dir;
    private CharacterController controller;
    public State playerState;
    public bool isMoving = false;
    // Start is called before the first frame update
    void Start()
    {
   
        dir = this.transform.GetComponent<PlayerDir>();
        controller = this.GetComponent<CharacterController>();
        playerState = State.Idle;
    }

    // Update is called once per frame
    void Update()
    {
   
        float distance = Vector3.Distance(dir.TargetPosition, transform.position);
        if (distance > 0.3f)
        {
   
            isMoving = true;
            controller.SimpleMove(transform.forward * speed);
            playerState = State.Walk;
        }
        else
        {
   
            isMoving = false;
            playerState = State.Idle;
        }
    }
}

PlayerDir玩家朝向问题

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

public class PlayerDir : MonoBehaviour
{
   
    public GameObject effect_Click;
    // Start is called before the first frame update
    private
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值