Home > other >  The realization of the fastest in the Unity3D implementation through keyboard control vision process
The realization of the fastest in the Unity3D implementation through keyboard control vision process

Time:09-23

A great god for help! Because of the need to quickly implement a simple to use the keyboard operation point of view on the function of roaming, need detailed process!!!

CodePudding user response:

 if (Input GetKeyDown (KeyCode. UpArrow)) {lens forward code} 

The same KeyCode. DownArrow KeyCode. LeftArrow KeyCode. RightArrow

CodePudding user response:

Camera movement code
 
GameObject _mainCamera;
Vector3 Vec3;
Int DIRFlag;
Int Vect;

//Use this for initialization
Void the Start ()
{
DIRFlag=1;
Vect=1;
Vec3=new Vector3 ();
MainCamera _mainCamera=GameObject. FindWithTag (" ");
}

//Update is called once per frame
Void the Update ()
{
Vec3=_mainCamera. The transform. The position;

If (Input. GetKeyDown (KeyCode. UpArrow))
{
Vect +=1;
}
If (Input. GetKeyDown (KeyCode. DownArrow))
{
If (Vect & gt; 0)
{
Vect -=1;
}
}

//
If (Input. GetKeyDown (KeyCode. W))
{
DIRFlag=0;
}

If (Input. GetKeyDown (KeyCode. S))
{
DIRFlag=1;
}

If (Input. GetKeyDown (KeyCode. D))
{
DIRFlag=2;
}

If (Input. GetKeyDown (KeyCode. A))
{
DIRFlag=3;
}


If (DIRFlag==0)
{
Vec3 +=new Vector3 (Vect, 0, 0);
}
Else if (DIRFlag==1)
{
Vec3 -=new Vector3 (Vect, 0, 0);
}
Else if (DIRFlag==2)
{
Vec3 +=new Vector3 (0, Vect, 0);
}
Else if (DIRFlag==3)
{
Vec3 -=new Vector3 (0, Vect, 0);
}

_mainCamera. The transform. The position=Vec3;
}
  • Related