I want that my shotgun would shot where it points. But now it only shoots left or right. How can i make it shoot where i point. My shotgun follows cursor.
My script:
var Spawn : GameObject;
var speed : float;
var bullet : Rigidbody2D;
var facingR : boolean;
var CanFire : boolean;
var FireRate : float;
function Start () {
facingR = true;
CanFire = true;
}
function Update () {
if(Input.GetKeyDown(KeyCode.A)) {
facingR = false;
}
if(Input.GetKeyDown(KeyCode.D)) {
facingR = true;
}
if(Input.GetButton("Fire1")){
Fire();
}
}
function Fire() {
if(facingR == true && CanFire == true) {
clone = Instantiate(bullet, Spawn.transform.position, Spawn.transform.rotation);
clone.AddForce(Vector2.right * speed);
audio.Play();
CanFire = false;
yield WaitForSeconds (FireRate);
CanFire = true;
}
if(facingR == false && CanFire == true) {
clone = Instantiate(bullet, Spawn.transform.position, Spawn.transform.rotation);
clone.AddForce(Vector2.right * -speed);
audio.Play();
CanFire = false;
yield WaitForSeconds (FireRate);
CanFire = true;
}
}