Готовый перевод C# Game Programming Cookbook for Unity 3D / Программирование игр на Unity 3D C#. Книга готовых решений.: 2.2.6 BaseInputController.cs
Входные контроллеры обеспечивают ввод для использования контроллера игрока.BaseInputController.cs выглядит следующим образом:
public class BaseInputController : MonoBehavior
{
// directional buttons
public bool Up;
public bool Down;
public bool Left;
public bool Right;
// fire / action buttons
public bool Fire1;
// weapon slots
public bool Slot1;
public bool Slot2;
public bool Slot3;
public bool Slot4;
public bool Slot5;
public bool Slot6;
public bool Slot7;
public bool Slot8;
public bool Slot9;
public float vert;
public float horz;
public bool shouldRespawn;
public Vector3 TEMPVec3;
private Vector3 zeroVector = new Vector3(0,0,0);
public virtual void CheckInput ()
{ // override with your own code to deal with input
horz=Input.GetAxis ("Horizontal");
vert=Input.GetAxis ("Vertical");
}
public virtual float GetHorizontal()
{ // returns our cached horizontal input axis value
return horz;
}
public virtual float GetVertical()
{ // returns our cached vertical input axis value
return vert;
}
public virtual bool GetFire()
{
return Fire1;
}
public bool GetRespawn()
{
return shouldRespawn;
}
public virtual Vector3 GetMovementDirectionVector()
{
// temp vector for movement dir gets set to the value of an
// otherwise unused vector that always has the value of 0,0,0
TEMPVec3=zeroVector;
// if we’re going left or right, set the velocity vector’s X
// to our horizontal input value
if(Left || Right)
{
TEMPVec3.x=horz;
}
// if we’re going up or down, set the velocity vector’s X to // our vertical input value if(Up || Down)
{
TEMPVec3.y=vert;
}
// return the movement vector
return TEMPVec3;
}
}
Внимание! Этот перевод, возможно, ещё не готов.
Его статус: идёт перевод
Переведено на Нотабеноиде
http://notabenoid.org/book/55263/242445
Переводчики: ilia1395
Настройки
Готово:
