var crosshairTexture : Texture2D;
var prefabBullet:Transform;
var shootForce:float;
var projectile: Rigidbody;
var speed = 20;
Screen.showCursor = false;
function OnGUI () {
var mousePos = Event.current.mousePosition;
GUI.DrawTexture( Rect( mousePos.x - (crosshairTexture.width/2), mousePos.y - (crosshairTexture.height/2),crosshairTexture.width, crosshairTexture.height), crosshairTexture);
}
function Update ()
{
var mousePos = Event.current.mousePosition;
if(Input.GetMouseButton (0) )
{
var instantiatedProjectile : Rigidbody = Instantiate(projectile,transform.position, transform.rotation);
instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (mousePos.x,mousePos.y, 0));
}
}
Already asked this previously - hope this isnt against the site rules but I thought Id get a few opinions - im rather stumped here.
Im attempting to have a 2d shooter. The character should be able to shoot by mouse press and a projectile shoot towards the current mouse x&y.
At present with the code above, the mouse x and y vector points are found. Its attached to a GUITexture cross hair. It should shoot to the mouse x and y and 0 on z axis however, it isnt doing so ![]()
Please could you point me in the right direction with this (no pun intended really :P)
Cheers