44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using UnityEngine;
|
|
|
|
public class charactercontroller : MonoBehaviour
|
|
{
|
|
private float itsVelocity = 30f;
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
|
|
{
|
|
base.transform.Rotate(new Vector3(0f, (0f - Time.deltaTime) * itsVelocity * 4f, 0f));
|
|
}
|
|
else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
|
|
{
|
|
base.transform.Rotate(new Vector3(0f, Time.deltaTime * itsVelocity * 4f, 0f));
|
|
}
|
|
if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
|
|
{
|
|
base.transform.position -= base.transform.forward * Time.deltaTime * itsVelocity;
|
|
}
|
|
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
|
|
{
|
|
base.transform.position += base.transform.forward * Time.deltaTime * itsVelocity;
|
|
}
|
|
float num = 50f;
|
|
if (base.transform.position.z >= num)
|
|
{
|
|
base.transform.position = new Vector3(base.transform.position.x, base.transform.position.y, num);
|
|
}
|
|
if (base.transform.position.z <= 0f - num)
|
|
{
|
|
base.transform.position = new Vector3(base.transform.position.x, base.transform.position.y, 0f - num);
|
|
}
|
|
if (base.transform.position.x >= num)
|
|
{
|
|
base.transform.position = new Vector3(num, base.transform.position.y, base.transform.position.z);
|
|
}
|
|
if (base.transform.position.x <= 0f - num)
|
|
{
|
|
base.transform.position = new Vector3(0f - num, base.transform.position.y, base.transform.position.z);
|
|
}
|
|
}
|
|
}
|