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";
}
}
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";
}
}