- Home /
Have a problems with a values
video of the problem : https://www.youtube.com/watch?v=wTWatycLKW8&feature=youtu.be
private AudioSource SPR;
public Animator MazzleAnim;
public Animator ShotingSAnim;
public Animator ReloudingAnim;
public float fireRate = 0.5f;
public float Relouding = 0.5f;
float NextRelouding = 0.5f;
float nextFire = 0.0f;
public float CorantineOfReloadingText = 0f;
public int AmmoCount = 7;
public int AllBullet = 30;
public int MaxBulletInHolder = 7;
public GameObject OverheatText;
public GameObject ReloudingText;
public Text AmmoUI;
public Text AllAmmoUI;
void Start ()
{
Debug.Log("Welcome to SniperShot and way i write this anybody hear me!");
AmmoUI.text = AmmoCount.ToString ();
AllAmmoUI.text = AllBullet.ToString ();
SPR = GetComponent<AudioSource> ();
}
IEnumerator TSetActive ()
{
{
yield return new WaitForSeconds (CorantineOfReloadingText);
OverheatText.SetActive (false);
}
}
IEnumerator TRelouding ()
{
{
yield return new WaitForSeconds (CorantineOfReloadingText);
ReloudingText.SetActive (false);
AllBullet = AllBullet - AmmoCount - MaxBulletInHolder;
AmmoCount = MaxBulletInHolder;
AmmoUI.text = AmmoCount.ToString ();
AllAmmoUI.text = AllBullet.ToString ();
}
}
void Update ()
{
if (Input.GetButtonDown ("Fire1") && Time.time > nextFire & AmmoCount > 0 & (Time.timeScale == 1))
{
nextFire = Time.time + fireRate;
RifleFire ();
OverheatText.SetActive (true);
StartCoroutine (TSetActive ());
AmmoCount = AmmoCount -1;
AmmoUI.text = AmmoCount.ToString ();
}
if (Input.GetButtonDown ("Reload") && Time.time > NextRelouding & AllBullet > 0 & (Time.timeScale == 1))
{
NextRelouding = Time.time + Relouding;
ReloudingAnim.Play ("SniperShotPReloud");
SPR.Play ();
ReloudingText.SetActive (true);
OverheatText.SetActive (false);
StartCoroutine (TRelouding ());
StopCoroutine (TSetActive ());
}
if (AllBullet <= -1)
{
//Debug.Log ("d");
AllBullet = 0;
AmmoCount = MaxBulletInHolder;
AmmoUI.text = AmmoCount.ToString ();
AllAmmoUI.text = AllBullet.ToString ();
}
if (Time.timeScale == 0)
{
} else
{
transform.position = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x , Input.mousePosition.y, 10f));
}
//if(Time.timeScale == 1)
//{
//transform.position = Camera.main.ScreenToWorldPoint (new Vector3 (Input.GetAxis ("XControll"), (Input.GetAxis ("YControll"))));
//}
}
void RifleFire ()
{
if (Time.timeScale == 0)
{
Debug.Log ("timeScale == 0 Shooting is disabled");
}
else
{
MazzleAnim.Play ("SniperShotMazzleAnim");
ShotingSAnim.Play ("SniperShotShotS");
}
}
}
Answer by Ymrasu · Feb 22, 2019 at 05:24 PM
It helps if you give more information about your problem whenever you ask a question. Though I can see you are having an issue with your bullet counts when reloading right? Is ammocount the ammo in your weapon, allbullet the amount left over, and maxbulletinholder just the max amount you want in the weapon? If this is the case, then this might help:
yield return new WaitForSeconds (CorantineOfReloadingText);
ReloudingText.SetActive (false);
int reloadAmount = MaxBulletInHolder - AmmoCount;
if(AllBullet >= reloadAmount) {
AmmoCount += reloadAmount;
AllBullet -= reloadAmount;
} else {
AmmoCount += AllBullet;
AllBullet = 0;
}
AmmoUI.text = AmmoCount.ToString ();
AllAmmoUI.text = AllBullet.ToString ();
Thanks this is works very good ! make a Replies for this to get your answer.
Your answer
Follow this Question
Related Questions
Slider.value won't change to INT 1 Answer
Major int interacting with lesser float 1 Answer
Convert Text to float 3 Answers
How do Generate Random Unique int ? 1 Answer
Is There A Way To Cast On 1 Returning Value 2 Times? 5 Answers