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 09:34:12 +00:00
|
|
|
float scrollingTextureProgress = 0;
|
|
|
|
public float scrollingTextureSpeedMult = 1;
|
|
|
|
public Renderer scrollingTextureRenderer;
|
|
|
|
|
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
|
|
|
}
|
2024-08-17 09:34:12 +00:00
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if(scrollingTextureRenderer)
|
|
|
|
{
|
|
|
|
scrollingTextureProgress += Time.deltaTime * speed * scrollingTextureSpeedMult;
|
|
|
|
scrollingTextureRenderer.material.SetTextureOffset("_MainTex",
|
|
|
|
new Vector2(0, scrollingTextureProgress));
|
|
|
|
}
|
|
|
|
}
|
2024-08-16 23:09:01 +00:00
|
|
|
}
|