Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by zak666 · Mar 04, 2017 at 01:17 AM · firenext

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";
 
 }
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DCordoba · Mar 04, 2017 at 04:36 AM 0
Share

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:

  1. is the same write && OverheatedT == true to write simply && OverheatedT but you make a less comparission

  2. look for IndavidualScore component on each frame is very expensive, better put this and the search for $$anonymous$$issionControll inside a Start method

  3. in 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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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";
 
 }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DCordoba · Mar 04, 2017 at 10:00 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

64 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges