- Home /
Question by
JPiiONEFOURONE · Jun 20, 2012 at 06:19 PM ·
mousecursorshoot
Shoot at mouse cursor
Hey guys,
I'm having a little problem with my current unity project. It is quite difficult for me to type out the problem, so instead I have made a short video showing my problem.
This is the current script
HeadRotate.js
#pragma strict
var position : Rect; var crosshairTexture : Texture2D;
function Update ()
{
var position = Input.mousePosition;
var newposition = Vector3(position.x,position.y,-camera.main.transform.position.z);
var lastposition = camera.main.ScreenToWorldPoint(newposition);
transform.LookAt(lastposition);
}
function OnGUI ()
{
position = Rect( Input.mousePosition.x - (crosshairTexture.width / 2), (Screen.height - Input.mousePosition.y) - (crosshairTexture.height / 2), crosshairTexture.width , crosshairTexture.height );
GUI.DrawTexture( position , crosshairTexture );
}
If anyone can help to fix this, please answer.
Thanks,
JPiiONEFOURONE
Comment
Your answer
Follow this Question
Related Questions
Attaching position of an object in game to position of cursor on screen 0 Answers
Shoot at Mouse Cursor 1 Answer
Shooting with camera on rails 4 Answers
Shooting at mouse position 1 Answer
Unity 3D Screen.lockCursor Problems 2 Answers