赞
踩
本文主要总结实现角色移动的解决方案。
1. 创建脚本:PlayerController
2. 创建游戏角色Player,在Player下挂载PlayerController脚本
3. 把Camera挂载到Player的子物体中,调整视角,以实现相机跟随效果
3. PlayerController脚本代码如下:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { public float speed = 5.0f; // Start is called before the first frame update void Start() { Transform transform = GetComponent<Transform>(); } // Update is called once per frame void Update() { Move(); } private void Move() { float horizontalInput = Input.GetAxis("Horizontal"); float verticalInput = Input.GetAxis("Vertical"); Vector3 moveingVec = new Vector3(horizontalInput, 0f, verticalInput) * Time.deltaTime * speed; transform.Translate(moveingVec); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。