Hey I’m using this simple code for my player to shoot. But how do I get the player to shoot in each direction of the arrow keys? so far he only shoots right.
using UnityEngine;
using System.Collections;
public class arrowKeysShoot : MonoBehaviour {
public Transform Gun;
// Update is called once per frame
void Update () {
if (Input.GetKeyDown ("up")) {
Instantiate(Gun, transform.position,Quaternion.identity);
}
}
}
How can I get him to shoot up when up is pressed and etc for the other directions?
Thank you!
public class arrowKeysShoot : MonoBehaviour {
public GameObject Gun;
public GameObject bulletgo;
public int shootforce;
// Update is called once per frame
void Update () {
if (Input.GetKeyDown ("up")) {
GameObject bullet = Instantiate (bulletgo, Gun.transform.position, Gun.transform.rotation) as GameObject;
bullet.rigidbody2D.AddForce (bullet.transform.forward * shootforce);
}
}
}
u might want to change the bullet.transform.forward to bullet.transform.up if u want to change the axis it works on
i just dont know on what axis u work on