2024-08-16 23:09:01 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class ConveyorBelt : MonoBehaviour
|
|
|
|
{
|
2024-08-17 08:57:32 +00:00
|
|
|
Rigidbody _rb;
|
|
|
|
Rigidbody rb { get { if (!_rb) _rb = GetComponent<Rigidbody>(); return _rb; } }
|
|
|
|
|
2024-08-16 23:09:01 +00:00
|
|
|
public float speed = 1;
|
|
|
|
|
2024-08-17 08:57:32 +00:00
|
|
|
Vector3 startPosition;
|
2024-08-16 23:09:01 +00:00
|
|
|
|
2024-08-17 08:57:32 +00:00
|
|
|
private void Start()
|
2024-08-16 23:09:01 +00:00
|
|
|
{
|
2024-08-17 08:57:32 +00:00
|
|
|
startPosition = rb.position;
|
|
|
|
}
|
2024-08-16 23:09:01 +00:00
|
|
|
|
2024-08-17 08:57:32 +00:00
|
|
|
private void FixedUpdate()
|
|
|
|
{
|
|
|
|
rb.position = startPosition;
|
|
|
|
Vector3 targetSpeed = speed * transform.forward;
|
|
|
|
rb.MovePosition(rb.position + targetSpeed * Time.deltaTime);
|
2024-08-16 23:09:01 +00:00
|
|
|
}
|
|
|
|
}
|