Unity(第十七部)Unity自带的角色控制器

组件Character Controller 中文角色控制器

csharp 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class player : MonoBehaviour
{
	private CharacterController player;
	void Start()
	{

		player= GetComponent<CharacterController>();
	}


	void Update()
	{

		//水平轴
		float horizontal = Input.GetAxis("Horizontal");
		//垂直轴
		float vertical = Input.GetAxis("Vertical");
		//创建成一个方向向量
		Vector3 dir = new Vector3(horizontal, 0, vertical);
		//打印向量
		//Debug.DrawRay(transform.position, dir, Color.red); 
		//朝向该方向移动
		//无重力影响
		player.Move(dir);
		//有重力影响
		//	player.SimpleMove(dir);


	}
}
相关推荐
xcl09252 小时前
北京24小时自助健身房系统软件开发实战:从架构到部署全流程指南
java·spring boot·架构
一 乐4 小时前
动漫书销售商城|基于springboot + vue动漫书销售商城(源码+数据库+文档)
java·数据库·vue.js·spring boot·毕业设计
598866753@qq.com4 小时前
Codex与Unity
unity·游戏引擎
卓怡学长4 小时前
w214基于jsp知道特产网
java·intellij-idea
步行cgn4 小时前
Spring 注解使用详解
java·spring
一条小小yu4 小时前
Spring IoC的理解
java·后端·spring
落魄实习生5 小时前
Agent Scope Java 2.x 系列【7】工具使用
java·开发语言·ai
旺仔学长 哈哈5 小时前
springboot钓鱼爱好者交流平台APP设计与实现
java·spring boot·mysql·充电桩管理系统
淡海水5 小时前
01-03-认知篇-C#内存模型深度解析
unity·c#·游戏引擎·.net·gc