键盘控制人物移动

using UnityEngine;
using System.Collections;
using Assets.Model;

public class PlayerMove : MonoBehaviour {

// Use this for initialization
private PlayerAnimation m_ScriptPlayerAnimation;
public int PlayerMoveSpeed;
private UnityEngine.Vector3 MoveDistanceX, MoveDistanceY;
private CharacterController m_CharacterController;
private UnityEngine.Vector3 TargetPostion;
public int m_State;
private MoveDTO SendDto;
private string SendStr;
void Start () {
m_ScriptPlayerAnimation = this.GetComponent<PlayerAnimation>();

SendDto = new MoveDTO();
SendDto.name = GameInfo.GetInstance().MyHeroModel.name;
SendDto.map = GameInfo.GetInstance().MyHeroModel.map;
m_State = PlayerState.Idle;
PlayerMoveSpeed = 6;
m_CharacterController = this.GetComponent<CharacterController>();
if (gameObject.name == "jiansheng(Clone)")
PlayerMoveSpeed = -PlayerMoveSpeed;
}

// Update is called once per frame
void Update () {
MoveDistanceX = transform.right * PlayerMoveSpeed * Input.GetAxis("Horizontal");
MoveDistanceY = transform.forward * PlayerMoveSpeed * Input.GetAxis("Vertical");
if (MoveDistanceX + MoveDistanceY == UnityEngine.Vector3.zero)
m_ScriptPlayerAnimation.MyState = PlayerState.Idle;
else
{

m_CharacterController.SimpleMove(MoveDistanceX + MoveDistanceY);
m_ScriptPlayerAnimation.MyState = PlayerState.Move;
//发送自己的位置、状态信息给服务器

SendDto.Point = new Assets.Model.Vector3(transform.position);
SendDto.Rotation = new Assets.Model.Vector4(transform.rotation);
SendDto.Dir = PlayerState.Move;
SendStr = Coding<MoveDTO>.encode(SendDto);

NetWorkScript.getInstance().sendMessage(Protocol.MAP, 0, MapProtocol.MOVE_CREQ, SendStr);
}

/* if(Input.GetAxis("Fire1")>0)
m_State = PlayerStates.attack1;
else if (Input.GetAxis("Fire2") > 0)
m_State = PlayerStates.attack2;
else if (Input.GetAxis("Fire3") > 0)
m_State = PlayerStates.skill;*/
}
}

时间: 2025-01-31 03:49:38

键盘控制人物移动的相关文章

用键盘控制DIV &amp;&amp; Div闪烁

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

AS3键盘控制

第一种方式: package com.game.keymanager { import flash.display.Stage; import flash.events.KeyboardEvent; import flash.ui.Keyboard; import flash.utils.Proxy; import flash.utils.flash_proxy; /** * The KeyObject class recreates functionality of * Key.isDown

IOS开发学习笔记-(2)键盘控制,键盘类型设置,alert 对话框

一.关闭键盘,放弃第一响应者,处理思路有两种 ① 使用文本框的 Did End on Exit 绑定事件 ② UIControl on Touch 事件 都去操作 sender 的  resignFirstResponder #import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UITextField *txtUserName; @pro

纯js实现用键盘控制DIV上下左右+放大缩小与变色

//用键盘控制DIV,红色方块为键盘操作区域,您可以进行如下操作:左右控制;背景变为绿色;背景变为黄色;背景变为蓝色放大或缩小用键盘控制DIV,红色方块为键盘操作区域,您可以进行如下操作:  上:↑ 下:↓ 左:← 右:→  Ctrl + 1 : 背景变为绿色  Ctrl + 2 : 背景变为黄色  Ctrl + 3 : 背景变为蓝色  Ctrl + ↑ : 放大  Ctrl + ↓ : 缩小 <!-- Author: XiaoWen Create a file: 2017-01-10 19:0

关于用过控制人物移动的方法

在这里将收集更新有关,控制移动的方法. 1.通过WSAD控制人物的前后移动的方法(一) 1 public class PlayerMovemeng:monoBehaviour 2 { 3 //人物的移动速度 4 public float speed=6f; 5 //坐标的移动变化量 6 Vector3 movement; 7 Rigidbody playerRigidbody; 8 //与Ray发生碰撞的平面的Layer层数' 9 int FloorMask; 10 float camRayLe

JS实现用键盘控制DIV上下左右+放大缩小与变色

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

【Unity3D】使用鼠标键盘控制Camera视角(即时战略类游戏视角):缩进,拉远,旋转

今天写一个demo,要用到鼠标键盘控制三维视角,因此写了个脚本用于控制. 该脚本可以用于即时战略类游戏的视角,提供了缩进,拉伸,旋转.同时按住鼠标右键不放,移动鼠标可以实现第一人称视角的效果. 1 using UnityEngine; 2 using System.Collections; 3 4 public class CameraController : MonoBehaviour { 5 6 7 public float near = 20.0f; 8 public float far

键盘控制

先安装装turtlebot_teleop包: sudo apt-get install ros-indigo-joystick-drivers ros-indigo-turtlebot-teleop 先启动一个模拟的TurtleBot sudo apt-get install ros-indigo-joystick-drivers ros-indigo-turtlebot-teleop 启动RViz: rosrun rviz rviz -d `rospack find rbx1_nav`/sim

简单的使用键盘控制方块移动

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>键盘控制方块移动</title> <style> #box{ width: 50px; height: 50px; background-color: green; position: relative; left: 50px; top: 50p