Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CoinAnim : MonoBehaviour {
- public float speed = 2f; // швидкість руху монетки
- public bool direction = true; // напрямок руху
- float yMin; // початкова координата
- void Start() {
- yMin = transform.position.y; // ініціалізація початкової координати
- }
- void FixedUpdate() {
- if (transform.position.y > yMin + 1) { // якщо монетка вийшла за верхню межу
- direction = false; // змінюємо напрямок на ВНИЗ
- } else if (transform.position.y < yMin) { // якщо монетка вийшла за нижню межу
- direction = true; // змінюємо напрямок на ВГОРУ
- }
- float delta = speed * (direction ? 1 : -1) * Time.deltaTime; // шаг анімації
- transform.position += Vector3.up * delta; // зрушуємо платформу
- }
- }
Add Comment
Please, Sign In to add comment