I have a simple ray cast script and I want to attach a bullet it to it and a reload function. How would I go about doing that? Would be something similar to a melee script with animations but adding a requirement for reload after firing?I'll add my weapon raycast script when I get home to show you what I have so far!
You want to attach a raycast to the bullet or you want to shoot a bullet after a raycast check? And where does the reload come in? Your question is pretty vague. Try rewording it.
So what my goal is to have the weapon attached to the script to be able to shoot with r but with the bullet moving with the raycast and then to check if the weapon has a bullet if not it would needed to be reloaded with a timer and a animation attached. Is that better wording? I'm sorry i'm just really new to this. Here is my script so far. Code (JavaScript): var Effect : Transform; var TheDamage = 100; function Update () { var hit : RaycastHit; var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0)); if (Input.GetMouseButtonDown(0)) { if (Physics.Raycast (ray, hit, 100)) { var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(particleClone.gameObject, 2); hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver); } } }
It's definitely more clear now, thank you. What aspect are you struggling with? All of it? It seems like you have most of the logic sorted, except the timing aspect. For the ammo, just make another variable at the top called ammo and give it a starting value (say 10) and decrease it every time you shoot. If it's <= 0, start playing your animation and don't let the player shoot any more until that's done.
Alright, the next step is adding the bullet though to the weapon to shoot when I left click. I'm learning by tutorials each day so it becomes more understandable each time. So for the ammo var ammo = 10; then I get lost on what to add it too.....
You can store it on the gun, on the person, on the backpack- etc... Personally, I think realism lends itself quite well to the problem. The overall ammo that your player holds should be held on your player/inventory object really, like a general "pool", then when you "reload" a gun, the pool should drop by the max number of bullets the weapon can hold, which should "refill" the weapon. While firing, it's the gun's own ammo variable that falls, and hitting zero would maybe switch animations to "firing but nothing happening", or simply not allow you to fire at all, or automatically reload (depending on your preference).