Hello! Im trying to make a portal like game now and its going pretty well
And i can pick items up and throw them around but the problem is, I cant stick it to the center of the screen.
its following the mouse witch is really annoying!
Is there some code that enables me to pick up things via a crosshair or something?
Haven’t had a chance to test the following but it should put you on the right track.
void Update() {
if (Input.GetButtonDown("Fire1")) {
Ray ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width/2, Screen.height/2);
RaycastHit hit;
if (Physics.Raycast(transform.position, fwd, 10, out hit)))
{
// Do something with the hit.transform.position here
}
}
}
Assuming you don’t need the mouse visible you could just start the game with.
Screen.lockCursor = true;
http://unity3d.com/support/documentation/ScriptReference/Screen-lockCursor.html
Thank you! But i only got errors
It works now!
Locked the mouse position in the centre and added a DragRigidBody to the camera.
Thanks for you help!