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
-1
Question by Omerl_ahire · Feb 16, 2018 at 02:39 AM · unity 5intweaponsetweapon system

Can't set an int from seperate script

Hi I'm making a weapon grouping system for a mechwarrior style game.

I want the system to set the weapons group to an integer of 1,2,3 or 4 by getting the int "GroupNum" and weapon "Pwep" from a UI button's "ButtonValue" script when clicked, then changing the weapon's int "WeaponGroup" with the "SetFor*TYPE*" function in weapon array.
.

The problem I am having is that when the "SetFor*TYPE*" function is called the the "GroupNum" int (which is set to the correct int from the "ButtonValue" script) returns a NullExceptionError and does not set the weapon's "GroupNum".

Button Value script

 public class ButtonValue : MonoBehaviour {
 
     ButtonValue thisButton;
     public bool projectile;
     UIPWeaponValue Pwep;
 
 void Start () { 
         
         thisButton = this.GetComponent<ButtonValue>();
         //gets the weapon value of selected weapon if the bool is set to that type
         if (projectile == true) {
             Pwep = transform.GetComponentInParent<UIPWeaponValue>();            
         }
 }
   public void SetGroup() {
 
         FindObjectOfType<WeaponArray>().button = thisButton;
         //sets the selected weapons and calls the relevent fuction in weaponArray
         if (Pwep !=null) {
             FindObjectOfType<WeaponArray>().weapon = Pwep.gameObject;
             FindObjectOfType<WeaponArray>().SetForProjectile();
         }
 }

} Weapon Array Script

 public class WeaponArray : MonoBehaviour {
 
     List<int> WeaponGroup = new List<int>();
     
     public ButtonValue button;
     public GameObject weapon;
 
     void Start () {
         WeaponGroup.Add(1);
         WeaponGroup.Add(2);
         WeaponGroup.Add(3);
         WeaponGroup.Add(4);
     }
     public void SetForProjectile() {
         print(button.GroupNum);
         weapon.GetComponent<WeaponProjectileScript>().weaponGroup = button.GroupNum;
     }

It seems like the script cant find the weapons "weaponGroup" int but I dont know why, the "weapon" group int is a public int .

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Omerl_ahire · Feb 16, 2018 at 03:43 AM

Have fixed the problem, I was getting the wrong object in the "SetGroup" function so it was getting the button value instead of the weapon value I changes that and now it works fine.

Comment
Add comment · 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

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

151 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 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 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

Get the number of false bools in GameObject[] (array) 3 Answers

Trying to add 1 to a int. 2 Answers

Why my keypad shows 4x the number in input? 2 Answers

ChildCount without counting the children of the child ? 2 Answers

How to transfer time script to 24 hours and not decimals 1 Answer


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