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);


	}
}
相关推荐
RainCity12 小时前
Java Swing 自定义组件库分享(九)
java·笔记·后端
NE_STOP12 小时前
Docker--容器常用命令
java
摇滚侠12 小时前
MSYS2 Builds Hashes Cygwin Builds Hashes 区别
java
武子康12 小时前
Java-08 深入浅出 Mybatis 数据库多对多关系设计:中间表、映射与性能优化
java·后端·spring
无极低码12 小时前
wsdl转client使用wsimport,高版本openjdk不支持使用 JAX-WS
java
明夜之约12 小时前
Spring Cloud Gateway 深度解析:从路由原理到生产级网关实战
java·spring·spring cloud·gateway
Simon5231412 小时前
Spring Bean----5.27学习小记
java·学习·spring
ZJH__GO13 小时前
java项目-流水线线程池
java·开发语言
心前阳光13 小时前
Unity之PhotonServer使用注意
unity·游戏引擎
●VON13 小时前
鸿蒙NEXT ArkUI进阶:用CustomBuilder打造高定制化品牌页签栏
java·华为·harmonyos·鸿蒙·新特性