quality-control/Assets/Scripts/ConveyorBelt.cs

46 lines
1.2 KiB
C#
Raw Permalink Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2024-08-19 20:16:18 +00:00
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-19 20:16:18 +00:00
public AudioSource audioSource;
2024-08-19 17:19:41 +00:00
2024-08-17 08:57:32 +00:00
private void Start()
{
2024-08-19 20:47:13 +00:00
float length = audioSource.clip.length;
audioSource.time += Random.Range(0.2f * length, 0.4f * length);
2024-08-19 20:16:18 +00:00
audioSource.pitch = Random.Range(-0.05f, 0.05f) + speed / 2f;
2024-08-19 17:19:41 +00:00
2024-08-17 08:57:32 +00:00
startPosition = rb.position;
}
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));
}
}
}