Hi
I was doin a simulation project on a self checkout machine.
I was tryin to write a hit collider script for the scanner on the self checkout machine, Incase the object hits the scanner, it will display a message in a GUI box. I was trying it for just one item first a simple cube. I applied the code on the scanner, but dosent seem to work. I got to know that hitcollider can only be used on a maincamera, so i tried using raycast. I have applied raycast before but just on a FPS,to open doors,etc. i dont know how to apply it on an object.
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == “Cube”)
{
GUI.Label(Rect(10,10,200,30),“testing”);
}
}
////////////////////////////////////////
function Update()
{
var hit : RaycastHit;
if (Physics.Raycast(transform.position, transform.forward, hit, 1))
{
if(hit.collider.gameObject.tag==“Cube”)
{
GUI.Label(Rect(10,10,200,30),“testing”);
}
}
}
the transform.position is used for the FPS camera, what should I Use to apply it to an object??
I apologize but the situation is unclear (for me).
- How many game objects do you have ?
- What is the expected behavior ?
- What are their components / scripts ?
- For custom scripts, what are their code ?
- Any errors messages ?
i attached an image of the machine[/img]

Hi Akilae Tribe
I apologize but the situation is unclear (for me).
-
How many game objects do you have ?
I will use just around 5
-
What is the expected behavior ?
As I scan every item, i need a message to be displayed on the screen, the item name and price
-
What are their components / scripts ?
The component is just the scanner on the self checkout machine. casue once every item hits the scanner, the name and amount should be displayed.
-
Any errors messages ?
THe script does not give any error, but dosent work either.
“When nothing works … beat up a chicken.”
Something popped into my mind, but unless I am mistaken, you can only use GUI and GUILayout functions inside the function OnGUI ().
You’d better make a private variable, which contains a string.
You put the GUI.Label function inside OnGUI function…
It displays the content of the private string variable…
When you Raycast, if there is something (or nothing), you assign the content of the private string to…whatever is required (if there is nothing, you give the value “”, it should do it).
Hi Akilae
I dint understnd the raycasting part, How should I frame it in the code?
Keep your Raycast in the Update function, just move GUI.Label (blabla) inside a function called OnGUI.
private var textToDisplay : String = "";
function OnGUI ()
{
GUI.Label (position, textToDisplay);
}
function Update ()
{
if (Physics.Raycast)
if (object is cube)
textToDisplay = "cube";
else
textToDisplay = "";
}