- Home /
limit ammo script please:)
I ve got this basic raycast shooting script and i wanna limit ammo can someone tell me how?please=)
pragma strict
var Effect : Transform; var TheDammage = 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("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
Comment
pragma strict
var Effect : Transform; var TheDammage = 100;
function Update () {
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if (Input.Get$$anonymous$$ouseButtonDown(0))
{
if (Physics.Raycast (ray, hit, 100))
{
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.Send$$anonymous$$essage("ApplyDammage", TheDammage, Send$$anonymous$$essageOptions.DontRequireReceiver);
}
}
}
Use an integer for how much ammo you get to start with, then decrement it every time the user shoots. When said integer is zero, make them unable to shoot.
Your answer
![](https://koobas.hobune.stream/wayback/20220613141139im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Gun Ammo Help 3 Answers
Scavenger script woe... 1 Answer
When i shoot, the next shoot will have the bullet half way down the screen!!! 1 Answer
unity 2d create an ammo box 2 Answers
Trigger a void only once even is used by multiple scripts? 2 Answers