- Home /
Issues with Nextfire and Displaying a Overheat Bar....
Hi gang All my pew pew pew guns were working awesome until I thought it would be cool to put in a Overheat feature and a GUI bar ...
Think I have missed a step Somewhere (the Gui Bar stays at 0, and now I cannot shoot..)
SCRIPT A: (This is on MissionControll Game Object)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class IndavidualScore : Photon.MonoBehaviour {
public Text Myscore;
public Text MyLives;
public Text MissilesText;
public float Lives = 5;
public float Missiles;
public float GunOverHeatFL = 0;
public float CooldownTime;
public Image GunOverHeat;
public GameObject Overheated;
public bool OverheatedT = false;
public void LateUpdate(){
///Assign me things......
Myscore.text = ("" + PhotonNetwork.player.GetScore());
MyLives.text = Lives.ToString();
MissilesText.text = Missiles.ToString();
GunOverHeat.fillAmount = GunOverHeatFL / 100; //Sicne we cant use 100 as a 0.1, 0.8 act, Devide by 100 to bake 100 / 1
if (GunOverHeatFL > 99) {
// if you hit 100 overheat the guns.....
//you canot shoot again untill cooldown....
Overheated.SetActive(true);
OverheatedT = true;
}
if (GunOverHeatFL < 1 && OverheatedT == true) {
// set overherat to true.....
Overheated.SetActive(false);
OverheatedT = false;
}
//if you are overheated guns Jam, and this cooldown is activated....
if (OverheatedT = true) {
GunOverHeatFL -= 1 * Time.deltaTime * CooldownTime;
if (GunOverHeatFL < 1) {
OverheatedT = false;
}
}
}
}
SCRIPT B. (This is on out spawned player, using Gameobject.find to assign since spawned by photon. also signing on Start or Awake done seem to work for some reason.....)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerShoot : Photon.MonoBehaviour {
public float fireRate = 0.3f;
public float nextFire = 0.0f;
public GameObject MachGunTeamOneMine;
public GameObject MachGunTeamOne;
public GameObject MissionControll;
public IndavidualScore IDScore;
public void LateUpdate(){
/// on player spawn finda nd assign missioncontroll.....
if (MissionControll == null) {
MissionControll = GameObject.FindGameObjectWithTag ("MissionControll");
}
if (MissionControll != null) {
IDScore = this.gameObject.GetComponent<IndavidualScore> ();
}
if(Input.GetButtonDown("Fire1") && Time.time > nextFire && photonView.isMine)
{
nextFire = Time.time + fireRate;
if (IDScore.GunOverHeatFL < 100 && IDScore.Overheated == false) {
// if you are not on cooldown and gunheat is less then 100... PEW PEW PEW PEW.....
GameObject clone = Instantiate (MachGunTeamOneMine, transform.position, transform.rotation) as GameObject;
clone.tag = "MachGunTeamOneMine";
photonView.RPC ("RPCShoot", PhotonTargets.OthersBuffered);
//upon each shot make the Gun-Heat go up....
IDScore.GunOverHeatFL += 1;
}
}
}
[PunRPC]
public void RPCShoot(){
// SHOOT other bullet.
GameObject clone = Instantiate (MachGunTeamOneMine, transform.position, transform.rotation) as GameObject;
clone.tag = "MachGunTeamOneMine";
}
}
In script B you need to assign the IDScore
object, otherwise you will have a null exeption when reach line 29 IDScore.GunOverHeatFL
to do this you need to get the component from the $$anonymous$$issionControll
gameobject not from the current gameobject so change line 21 from IDScore = this.gameObject.GetComponent<IndavidualScore> ();
to IDScore = $$anonymous$$issionControll.GetComponent<IndavidualScore> ();
other things to is good to change, for good program$$anonymous$$g practice:
is the same write
&& OverheatedT == true
to write simply&& OverheatedT
but you make a less comparissionlook for
IndavidualScore
component on each frame is very expensive, better put this and the search for$$anonymous$$issionControll
inside aStart
methodin line 44 of the script A
GunOverHeatFL
can reach negative values, make sure to set it to 0 if this is less than 1, so inside the if of the line 45
hope this helps. sincerely.
Answer by zak666 · Mar 04, 2017 at 05:03 AM
Hi... (Wow how idd i miss i assigned it top itself..... RIP... my bad...) If looked in ti though I'm still unable to shoot...
Script A
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class IndavidualScore : Photon.MonoBehaviour {
public Text Myscore;
public Text MyLives;
public Text MissilesText;
public float Lives = 5;
public float Missiles;
public float GunOverHeatFL = 0;
public float CooldownTime;
public Image GunOverHeat;
public GameObject Overheated;
public bool OverheatedT = false;
public void LateUpdate(){
//------------------------------------------------------------------------------------------------------------------------
///Assign me things......
Myscore.text = ("" + PhotonNetwork.player.GetScore());
MyLives.text = Lives.ToString();
MissilesText.text = Missiles.ToString();
GunOverHeat.fillAmount = GunOverHeatFL / 100; //Sicne we cant use 100 as a 0.1, 0.8 act, Devide by 100 to bake 100 / 1
//------------------------------------------------------------------------------------------------------------------------
if (GunOverHeatFL > 99) {
// if you hit 100 overheat the guns.....
//you canot shoot again untill cooldown....
Overheated.SetActive(true);
OverheatedT = true;
}
//------------------------------------------------------------------------------------------------------------------------
if (GunOverHeatFL < 1 && OverheatedT == true) {
// set overherat to true.....
Overheated.SetActive(false);
OverheatedT = false;
}
//------------------------------------------------------------------------------------------------------------------------
//if you are overheated guns Jam, and this cooldown is activated....
if (OverheatedT = true) {
GunOverHeatFL -= 1 * Time.deltaTime * CooldownTime;
if (GunOverHeatFL < 1) {
if (GunOverHeatFL < 0) {
GunOverHeatFL = 0;
// stop overheat hitting -0 numbers....
}
OverheatedT = false;
}
}
//------------------------------------------------------------------------------------------------------------------------
}
}
Script player:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerShoot : Photon.MonoBehaviour {
public float fireRate = 0.3f;
public float nextFire = 0.0f;
public GameObject MachGunTeamOneMine;
public GameObject MachGunTeamOne;
public GameObject MissionControll;
public IndavidualScore IDScore;
//------------------------------------------------------------------------------------------------------------------------
public void Start (){
/// on player spawn finda nd assign missioncontroll.....
if (MissionControll == null) {
MissionControll = GameObject.FindGameObjectWithTag ("MissionControll");
}
if (MissionControll != null) {
IDScore = MissionControll.GetComponent<IndavidualScore> ();
}
}
//------------------------------------------------------------------------------------------------------------------------
public void LateUpdate(){
if(Input.GetButton("Fire1") && Time.time > nextFire && photonView.isMine)
{
nextFire = Time.time + fireRate;
if (IDScore.GunOverHeatFL < 100 && IDScore.OverheatedT) {
// if you are not on cooldown and gunheat is less then 100... PEW PEW PEW PEW.....
GameObject clone = Instantiate (MachGunTeamOneMine, transform.position, transform.rotation) as GameObject;
clone.tag = "MachGunTeamOneMine";
photonView.RPC ("RPCShoot", PhotonTargets.OthersBuffered);
//upon each shot make the Gun-Heat go up....
IDScore.GunOverHeatFL += 1;
}
}
}
//------------------------------------------------------------------------------------------------------------------------
[PunRPC]
public void RPCShoot(){
// SHOOT other bullet.
GameObject clone = Instantiate (MachGunTeamOneMine, transform.position, transform.rotation) as GameObject;
clone.tag = "MachGunTeamOneMine";
}
}
script A, in line 48 if (OverheatedT = true) {
you make a assign, so the gun is always overheated, I gess you want to make a comparission if (OverheatedT == true) {
or as I said before just if (OverheatedT) {
Your answer
Follow this Question
Related Questions
constant fire (transform) 2 Answers
exploding a car 4 Answers
fps shooting in the direction of character main cam 1 Answer
Stop Specific Audio on a Script with multiple Sounds? 2 Answers
Trying to fire a Projectile 2 Answers