Open notleeandrew opened 8 years ago
So, for this to work, you'll need to create a prefab to instantiate as a projectile. I've called mine projectile, but the beauty of programming is you can name it "ceiling cat is watching you masturbate", if you want to really confuse hackers.
using UnityEngine; using System.Collections;
public class Shooting : MonoBehaviour {
GameObject prefab;
void Start () {
prefab = Resources.Load ("projectile") as GameObject;
}
void Update () {
if (Input.GetMouseButtonDown(0)) {
GameObject projectile = Instantiate (prefab) as GameObject;
projectile.transform.position = transform.position + Camera.main.transform.forward *2;
Rigidbody rb = projectile.GetComponent<Rigidbody> ();
rb.velocity = Camera.main.transform.forward * 40;
}
}
}
this code works. it is easy to understand. wish i don't have a wish for this.
i want to be able to fire projectiles