Keyboard control character Movement

Source: Internet
Author: User

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;
Send your own location, status information to the server

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;*/
}
}

Keyboard control character Movement

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.