using UnityEngine;
public class PlayerController: MonoBehaviour
{
public float speed = 5f; // Скорость перемещения
void Update()
{
float moveX = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveX, 0, moveZ);
transform.Translate(movement * speed * Time.deltaTime);
}
}
using UnityEngine;
public class Collectible : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
Destroy(gameObject); // Удаляем объект при столкновении с игроком
}
}
}
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public Text scoreText; // Ссылка на UI текст для отображения счета
private int score = 0;
public void AddScore()
{
score++;
scoreText.text = "Score: " + score;
}
}
public class Collectible : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
FindObjectOfType<GameManager>().AddScore();
Destroy(gameObject);
}
}
}