quality-control/Assets/Scripts/ConveyorBelt.cs

42 lines
1.1 KiB
C#
Raw Normal View History

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