I want to instantiate a game object every time when the space key is pressed. Please help me with some solution below is my code-
public class arrow : MonoBehaviour {
public Rigidbody2D rb;
public float speed;
public GameObject arow;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float x = Input.GetAxis ("Horizontal");
if (x > 0) {
MoveRight ();
}
if (Input.GetKeyDown (KeyCode.Space)) {
Instantiate (arow);
}
}
void MoveRight(){
rb.velocity = new Vector2 (speed, 0);
}
void OnCollisionEnter2D(Collision2D col){
if (col.gameObject.tag == "ball") {
Destroy (gameObject);
}
}