using UnityEngine; using System.Collections.Generic; public class TriggerPlatform : MonoBehaviour { [Header("Настройки Шаров")] public List hazardBalls; [SerializeField] private float initialPushForce = 5f; // Начальный толчок для старта движения [SerializeField] private float triggerDelay = 0.5f; // Задержка перед началом движения private bool hasBeenTriggered = false; void Start() { // При старте убеждаемся, что все шары статичны foreach (GameObject ball in hazardBalls) { Rigidbody rb = ball.GetComponent(); if (rb != null) { rb.isKinematic = true; } if (ball.GetComponent() == null) { ball.AddComponent(); } } } private void OnCollisionEnter(Collision collision) { if (collision.gameObject.GetComponent() != null && !hasBeenTriggered) { hasBeenTriggered = true; Invoke("ActivateHazards", triggerDelay); } } private void ActivateHazards() { foreach (GameObject ball in hazardBalls) { Rigidbody rb = ball.GetComponent(); if (rb != null) { // 1. включаем физику rb.isKinematic = false; // 2. Определяем направление к игроку Vector3 direction = (transform.position - ball.transform.position).normalized; Vector3 pushDirection = (ball.transform.position - transform.position); pushDirection.y = 0; pushDirection = pushDirection.normalized; rb.AddForce(transform.forward * initialPushForce, ForceMode.Impulse); // Активируем скрипт RollingHazard для постоянного преследования игрока ball.GetComponent().StartPursuit(FindObjectOfType().transform); } } } }