- Home /
Ammo with ammobar problem.
Hi, I have made a ammo script by myself but I don't know how I do connect it with my ammobar. the full ammo = 1, and every shot needs to count with = 0.1. So can shoot 10 times max.
here's my script:
var sparks : ParticleEmitter; var Bullet : Transform; var spawnPoint : Transform; var speed = 350; var guiskin : GUISkin; var pos : Vector2 = new Vector2(20,40); var size : Vector2 = new Vector2(60,20); var BarEmpty : Texture2D; var BarFull : Texture2D; var maxAmmo : float = 100; var shots : float = 0;
function Start () {
sparks.active = false;
}
function OnGUI(){
GUI.DrawTexture(Rect(pos.x, pos.y, size.x, size.y), BarEmpty); GUI.DrawTexture(Rect(pos.x, pos.y, size.x * Mathf.Clamp01(maxAmmo), size.y), BarFull);
GUI.skin = guiskin;
if(GUI.Button(Rect(310,435,150,45), "Shoot")&& shots < maxAmmo){
var bullet = Instantiate(Bullet,GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.up * speed);
shots++; Shoot();
}
GUI.Label(Rect(52,458,120,25), "Ammo");
}
function Shoot(){
sparks.active = true; yield WaitForSeconds(0.5); sparks.active = false;
maxAmmo- shots =0.1;
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Scripts stop working in Maximize On View and testing on Android 0 Answers
pause menu on android phone 1 Answer
Need help with picking up items by typing "E" 0 Answers
AssetBundle Android 1 Answer