标签:
1,创建场景,添加角色 如下图
2,在角色下添加脚本
3,填写逻辑
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
public float speed = 6f;
Vector3 movement;
Rigidbody PlayerRididbody;
void Awake() {
PlayerRididbody = GetComponent<Rigidbody>();
}
void FixedUpdate () {
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
Move(h, v); //使player可以移动
}
void Move(float h, float v) {
movement.Set(h, 0f, v); // set movement ‘s value
movement = movement.normalized * speed * Time.deltaTime;
PlayerRididbody.MovePosition(transform.position + movement); //通过MovePosition()方法让主角移动
}
}
4,运行,使用上下左右键移动
版权声明:本文为博主原创文章,未经博主允许不得转载。
unity3d 5.0 SurvivalShooter(一) 角色移动
标签:
原文地址:http://blog.csdn.net/gongfu_li/article/details/46915675