Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FPSInput : MonoBehaviour
{
public float speed = 6.0f;
public float turnSpeed = 50f;
public float Rotationspeed = 3f;
private bool vprav = false;
private bool vlevo = false;
void Start()
{
}
void Update()
{
transform.Translate(0, (speed * Time.deltaTime), 0);
if (transform.rotation.y < 0)
{
if (vprav == true)
{
transform.Translate(Rotationspeed * Time.deltaTime, 0, 0);
}
}
if (transform.rotation.y > 0)
{
if (vlevo == true)
{
transform.Translate(-Rotationspeed * Time.deltaTime, 0, 0);
}
}
if (Input.GetKey(KeyCode.LeftArrow))
{
transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
vprav = true;
vlevo = false;
}
if (Input.GetKey(KeyCode.RightArrow))
{
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
vlevo = true;
vprav = false;
}
}
}
using System.Collections.Generic;
using UnityEngine;
public class FPSInput : MonoBehaviour
{
public float speed = 6.0f;
public float turnSpeed = 50f;
public float Rotationspeed = 3f;
private bool vprav = false;
private bool vlevo = false;
void Start()
{
}
void Update()
{
transform.Translate(0, (speed * Time.deltaTime), 0);
if (transform.rotation.y < 0)
{
if (vprav == true)
{
transform.Translate(Rotationspeed * Time.deltaTime, 0, 0);
}
}
if (transform.rotation.y > 0)
{
if (vlevo == true)
{
transform.Translate(-Rotationspeed * Time.deltaTime, 0, 0);
}
}
if (Input.GetKey(KeyCode.LeftArrow))
{
transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
vprav = true;
vlevo = false;
}
if (Input.GetKey(KeyCode.RightArrow))
{
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
vlevo = true;
vprav = false;
}
}
}