x


How to make a 2d mouse look script

Hello. I've been working on a 2d game, but I've run into a problem with a standard function. 1. How do you make a object rotate to face the cursor? and 2. How do you make the crosshair follow the mouse.

Thanks.

more ▼

asked Aug 23 '10 at 10:36 PM

GhostlyStudios gravatar image

GhostlyStudios
71 3 3 6

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Considering you have a GUI Crosshair texture, here's the code you use.

var crosshairTexture : Texture2D;

var position : Rect;

function Start() { position = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width, crosshairTexture.height ); }

function OnGUI() { GUI.DrawTexture(position, crosshairTexture);
}

...and that's how. about that 2d rotator thing... I absolutely have no idea. PS make sure to have the GUI Crosshair set into the script. remember, the script is in the camera!

more ▼

answered Sep 01 '10 at 12:30 PM

Not showing my name gravatar image

Not showing my name
107 8 9 19

(comments are locked)
10|3000 characters needed characters left

Try this answer. It should solve the 2D Rotation issue.

more ▼

answered Oct 01 '10 at 12:29 PM

Sebas gravatar image

Sebas
4k 12 18 45

link dont work anymore btw.

Apr 18 at 06:07 PM cowasockytommy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5086
x1038
x984

asked: Aug 23 '10 at 10:36 PM

Seen: 1950 times

Last Updated: Apr 18 at 06:08 PM