Unity How to Shoot an Arrow

  • Create an arrow-bullet like texture. Make sure the tip is pointing upwards in the image.
  • Create a prefab that is gonna shoot/spawn the arrows.
  • Attach this script:
ArrowShooter.cs
using UnityEngine;
using System.Collections;
 
public class ArrowShooter : MonoBehaviour {
 
	public float bulletCoolDown = 4.0f; // seconds
	private float bulletTimer = 0f;
 
	void Start () {		
	}
 
	// Update is called once per frame
	void Update () {
		bulletTimer += Time.deltaTime;
 
		if (bulletTimer > bulletCoolDown) {
			shoot();
		}
	}
 
	void shoot() {
		bulletTimer = 0f;		
		GameObject clone = (GameObject) Instantiate(Resources.Load("Arrow_Up"), transform.position, transform.rotation);
	}
}

Attach following script to your Arrow_Up prefab:

ArrowMove.cs
using UnityEngine;
using System.Collections;
 
public class ArrowMove : MonoBehaviour {
 
	public AudioClip shot;
 
	// Use this for initialization
	void Start () {
		AudioSource.PlayClipAtPoint(shot, transform.position);
	}
 
	// Update is called once per frame
	void FixedUpdate () {
		rigidbody2D.gravityScale = 0;
		rigidbody2D.AddForce(transform.up * 50f);
	}
 
	void OnCollisionEnter2D(Collision2D coll) {	
		Destroy (gameObject);
	}
}
Navigation
Print/export
Toolbox