54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
|
|
public class Conveior : MonoBehaviour
|
|
{
|
|
[SerializeField] float speed, conveyorSpeed; //una pentru obiect si alta pentru conveior
|
|
|
|
[SerializeField] Vector3 direction; // directia in care deplaseaza obiectul
|
|
|
|
[SerializeField] private List<GameObject> objectsOnBelt = new List<GameObject>(); //lista cu obiectele care se afla pe conveior
|
|
|
|
private Material material; //materialul conveiorului, cel care se va invarti
|
|
|
|
void Start()
|
|
{
|
|
material = GetComponent<Renderer>().material;
|
|
//Renderer.me
|
|
UnityEngine.Debug.Log(material.GetTexturePropertyNames()[0]);
|
|
foreach(var mat in material.GetTexturePropertyNames())
|
|
{
|
|
UnityEngine.Debug.Log(mat);
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
GetComponent<MeshRenderer>().material.mainTextureOffset += new Vector2(0,1) * conveyorSpeed * Time.deltaTime;
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
for (int i=0;i<=objectsOnBelt.Count - 1;i++)
|
|
{
|
|
//objectsOnBelt[i].GetComponent<Rigidbody>().AddForce(speed * direction);
|
|
Vector3 move = objectsOnBelt[i].transform.position + direction * speed * Time.deltaTime;
|
|
objectsOnBelt[i].GetComponent<Rigidbody>().MovePosition(move);
|
|
}
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
objectsOnBelt.Add(collision.gameObject);
|
|
UnityEngine.Debug.Log("Salt");
|
|
}
|
|
|
|
private void OnCollisionExit(Collision collision)
|
|
{
|
|
objectsOnBelt.Remove(collision.gameObject);
|
|
UnityEngine.Debug.Log("Salt");
|
|
}
|
|
}
|