2024-08-16 23:09:01 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2024-08-19 17:19:41 +00:00
|
|
|
public class ConveyorBelt : MonoBehaviour, IResetable
|
2024-08-16 23:09:01 +00:00
|
|
|
{
|
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-19 17:19:41 +00:00
|
|
|
public AudioClip conveyorClip;
|
|
|
|
public float volume = 0.25f;
|
|
|
|
private AudioSource _audioSource;
|
|
|
|
|
|
|
|
public void ResetMachine()
|
|
|
|
{
|
|
|
|
if (_audioSource)
|
|
|
|
{
|
|
|
|
_audioSource.Stop();
|
|
|
|
Destroy(_audioSource.gameObject);
|
|
|
|
_audioSource = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isActiveAndEnabled)
|
|
|
|
{
|
|
|
|
_audioSource = NAudio.Play(conveyorClip, transform.position, volume);
|
|
|
|
_audioSource.loop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-17 08:57:32 +00:00
|
|
|
private void Start()
|
2024-08-16 23:09:01 +00:00
|
|
|
{
|
2024-08-19 17:19:41 +00:00
|
|
|
ResetMachine();
|
|
|
|
|
2024-08-17 08:57:32 +00:00
|
|
|
startPosition = rb.position;
|
2024-08-18 20:01:23 +00:00
|
|
|
|
2024-08-19 00:05:50 +00:00
|
|
|
//scrollingTextureSpeedMult = -0.1625f * speed;
|
2024-08-17 08:57:32 +00:00
|
|
|
}
|
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
|
|
|
}
|