using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed = 5.0f;
void Update()
{
if (Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
}
}
using UnityEngine;
public class PlayerController : MonoBehaviour
{
void Start()
{
// Инициализация объекта
}
void Update()
{
// Обновление логики каждый кадр
}
}
public class Player : MonoBehaviour
{
public float speed = 5.0f;
void Update()
{
float move = Input.GetAxis("Vertical") * speed * Time.deltaTime;
transform.Translate(0, 0, move);
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Enemy")
{
Destroy(collision.gameObject);
}
}
using UnityEngine;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour
{
public Text scoreText;
private int score = 0;
void Update()
{
scoreText.text = "Score: " + score;
}
public void AddScore(int points)
{
score += points;
}
}
public class Player
{
private int health;
public int Health
{
get { return health; }
set { health = Mathf.Clamp(value, 0, 100); }
}
}
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
// Используйте кэшированные компоненты
rb.AddForce(Vector3.forward * 10);
}
[CreateAssetMenu(fileName = "New Weapon", menuName = "Weapon")]
public class Weapon : ScriptableObject
{
public string weaponName;
public int damage;
public float fireRate;
}
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed = 5.0f;
void Update()
{
float moveHorizontal = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
float moveVertical = Input.GetAxis("Vertical") * speed * Time.deltaTime;
transform.Translate(moveHorizontal, 0, moveVertical);
}
}
using UnityEngine;
public class Coin : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
Destroy(gameObject);
// Добавьте логику увеличения счета
}
}
}
using UnityEngine;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour
{
public Text scoreText;
private int score = 0;
public void AddScore(int points)
{
score += points;
scoreText.text = "Score: " + score;
}
}