Синтаксис:
Используется csharp
using UnityEngine;
public class Car_move : MonoBehaviour {
public float speed = 0.0f;
public float max_speed = 15.0f;
public float rozgon_speed = 0.05f;
private Rigidbody carRigidbody;
void Start() {
carRigidbody = GetComponent<Rigidbody>();
}
void Update() {
if (Input.GetKey("w")) {
if (speed < max_speed) {
speed += rozgon_speed;
}
}
if (!Input.GetKey("w")) {
if (speed > 0) {
speed -= 0.05f;
}
}
carRigidbody.AddForce(carRigidbody.transform.forward * speed * Time.deltaTime);
}
}
public class Car_move : MonoBehaviour {
public float speed = 0.0f;
public float max_speed = 15.0f;
public float rozgon_speed = 0.05f;
private Rigidbody carRigidbody;
void Start() {
carRigidbody = GetComponent<Rigidbody>();
}
void Update() {
if (Input.GetKey("w")) {
if (speed < max_speed) {
speed += rozgon_speed;
}
}
if (!Input.GetKey("w")) {
if (speed > 0) {
speed -= 0.05f;
}
}
carRigidbody.AddForce(carRigidbody.transform.forward * speed * Time.deltaTime);
}
}