If anyone has any suggestions on how to assign a “number” to an object OnTriggerEnter…
I’m trying to make a situation where boxes are moving through a conveyor belt and they reach an intersection. I would like the intersection to have 5 sides/belts. When a box arrives from either 5 sides I would like it to be assigned a “number” and then move in an order from first to last (first box that arrived to the intersection leaves first)…and as it leaves (OnTriggerExit) the intersection, script gives instructions to let the next (2,3,4 or 5) box to move.
So far I have different colliders for each side and one huge one in the middle being the OnTriggerExit. But I’m stuck as to how I can achieve this number system for the box to move in an order.
When a box arrives from either 5 sides you shoud add this box to the queue with Enqueue(box) method. When you want to take the first box from queue call Dequeue() method.
Thank you for this information, so far this is what I have:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Trigger : MonoBehaviour {
BoxMove BoxScript;
Queue MyQ = new Queue();
void Start (){
hiScript = GetComponent<BoxMove>();
}
void OnTriggerEnter ( Collider other ){
if( other.CompareTag( "StopTrigger" ) )
{
BoxScript.speed = 0 ;
myQ.Enqueue();
}
}
void Update () {
if (MyQ.Queue.Count<=4)
{ MyQ.Dequeue();
BoxScript.speed = 15 ;
}
}
}
I’m getting the following errors:
(22,25): error CS0103: The name myQ' does not exist in the current context (27,25): error CS1061: Type System.Collections.Queue’ does not contain a definition for Queue' and no extension method Queue’ of type `System.Collections.Queue’ could be found (are you missing a using directive or an assembly reference?)
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Trigger : MonoBehaviour {
BoxMove BoxScript;
Queue MyQ = new Queue();
void Start (){
BoxScript = GetComponent<BoxMove>();
}
void OnTriggerEnter ( Collider other ){
if( other.CompareTag( "StopTrigger" ) )
{
MyQ.Queue(); // I want to disable or modify speed of BoxScript here
}
}
void Update () {
if (MyQ.Count<=4)
{ MyQ.Dequeue(); // I want to enable or modify speed of BoxScript here
}
}
}
Thanks again, so I have tried to implement the Queue with Trigger but I am having trouble with Dequeue.
Dequeue is giving me "No overload for method which takes ‘1’ arguement
and Queue is having problems "Systems.Collections.Queue’ does not contain a definition for extension method Queue' of type System.Collections.Queue’ could be found (are you missing a using directive or an assembly reference?)
I have tried changing line 8 with Queue MyQ = new Queue<int>();
to rely on a numbered queue and writing to stop BoxScript separately.
which doesn’t work either.