Need Raycast mid screen, Help!

I want my GUI Crosshair to react when I click the mouse button. I’m guessing a solution to that would be to use Raycasting and setting it to be mid screen at all times regardless of mouse position. But how?

I’ve got the standard Mouse Look script in Java on my Character controller that controls the camera and I guess thats the code that also controls the mouse click function right now, but since I don’t know java I can’t tell where in the script it commands anything other then movement of the camera.

Can anybody help me with some code that overrides the current mouse click function and sets it to mid screen at all times?

Thanks in advance :slight_smile:

You should probably start with some tutorials. Using the excuse that you don’t know Java is not valid in Unity whatsoever. Java/C# mostly only have syntax differences, the rest is Unity stuff that is shared.

var MyVar : GameObject;
MyVar.name = "new name";
MyVar.transform.position = Vector3(0,0,0);
GameObject MyVar;
MyVar.name = "new name";
MyVar.transform.position = new Vector3(0,0,0);

To accomplish this you could just make a new script that checks if you clicked and will automatically raycast the center of the screen. You don’t need to force the mouse to a position, nor do it all in one script. Look up the Camera documentation to turn screen points into world points, etc.

Well I should’ve specified for you aaro4130 that I don’t know any programming language. And trust me all i do is look at tutorials.

Thanks anyway.

FYI, Java isn’t even supported by Unity. Javascript != Java. They are completely different languages.

@GFFG , There are lots of nice code examples in the documentation to go with the functions, so like I have said you should check out the Camera sections :). Sorry I came off so harsh there, dealing with some tense situations at the moment.

1 Like

No problem buddy, I appreciate your help :slight_smile: I’ll check out the Camera sections right away.