I’m working on this RPG and i took a while figuring this out, its a smallish script (javascript) where if you press the button it will shoot out something like a ball that you can attach particles to then make a prefab and you got your projectile, such as a waterbolt. and this “waterbolt” fires from a small sphere that has no collider and the mesh is turned off too, so the sphere can be parented to a cane or something and when the button is clicked the waterbolt goes flying forward.
You Need:
*A 2D Texture
*A Audio (still works if you dont have a clip)
*The Projectile its self in a prefab so you can fire it over and over again.
*And A small Sphere With Collisions Turned off and Parented to the Player. “mesh render off”
// Draws 2 buttons, one with an image, and other with a text
// And print a message when they got clicked.
var btnTexture : Texture;
var bullitPrefab:Transform;
var SpellSound : AudioClip;
function OnGUI() {
if (!btnTexture) {
Debug.LogError("Please assign a texture on the inspector");
return;
}
if (GUI.Button(Rect(200,450,50,50),btnTexture))
{
audio.PlayOneShot(SpellSound);
var bullit = Instantiate(bullitPrefab,
GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 4000);
}
}
working on collisions so when it hits something tagged with enemy it decreases there health and when the spell hits something it kills it the “waterbolt” or blows up. What “I” need is some help though, i cant seem to make so only when you click the button does it shot the “waterbolt” i can click anywhere and it still shoots! >.<
EDIT* 5/23/11 4:32 PM Thanks to ZioRed