x


how do I shoot where my cross hair points?

I have a crosshair on the main camara and a fire function on my gun (zap) but when I fire the projectiles (standard Roll A Ball)it fires to right of the camera and right from where the crosshair points.

Crosshair function java (under Main Camera) var crosshairTexture : Texture2D; var position : Rect; static var OriginalOn = true;

function Update() // Start will only get the screen size once. it will not refresh it. the turn around is to use function Update() instead. { position = Rect((Screen.width - crosshairTexture.width) / 2, (Screen.height - crosshairTexture.height) /2, crosshairTexture.width, crosshairTexture.height); }

function OnGUI() { if(OriginalOn == true) { GUI.DrawTexture(position, crosshairTexture); } }

Fire function C# (under the gun)

using UnityEngine; using System.Collections;

public class fire : MonoBehaviour { public GameObject projectile; public float fireRate = 0.5F; private float nextFire = 0.0F;

// Update is called once per frame
void Update () {
if (Input.GetButton("Fire1") && Time.time > nextFire) {
        nextFire = Time.time + fireRate;
        GameObject clone = Instantiate(projectile, transform.position, transform.rotation) as GameObject as GameObject;
    }
}

}

more ▼

asked May 16 '12 at 11:04 AM

safforn142 gravatar image

safforn142
0 1 1

Please format your code correctly by highlighting the entire code and pressing the 101010 button.

May 16 '12 at 11:17 AM Kleptomaniac
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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:

x330
x153
x111
x104

asked: May 16 '12 at 11:04 AM

Seen: 498 times

Last Updated: May 16 '12 at 11:17 AM