• 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 SuperPurpleByte · Sep 25, 2014 at 11:55 PM · booleanboolrocket

How to change bool values from one controlling script to a receiver?

I Have a bool on a rocket that when false it will fire the rocket. Then I have a control script that will index all the rockets with a specific tag in to an array. The problem I am having is changing the value of the bool from the control .

This is what I have so far

 using UnityEngine;
 using System.Collections;
 
 public class MissileFireSystem : MonoBehaviour
 {
     public GameObject[] rockets;
     public string firingMethod;//what input axis is being used?
     public int rocketToFire;
     
     // Use this for initialization
     void Start()
     {
         rockets = GameObject.FindGameObjectsWithTag("rocket#1");//getting all of the rockets, rocket#1 refers to the hydra 70 rockets 
 
             for (int i=0; i>rockets.Length; i++) 
                 {
                 RocketPropulsion rocketComponent = rockets [i].GetComponent<RocketPropulsion> ();
                 }
         
     }
     
     // Update is called once per frame
     void Update()
     {
         if (Input.GetButtonDown(firingMethod))
         {
             rockets[rocketToFire].rocketComponent.weaponSafe = false;//this will fire the rocket
             print (rockets[rocketToFire]);
 
             rocketToFire = rocketToFire + 1;
         }
 
 
 
 
     }
 }


On the second script is just

when weaponSafe = false fire the rocket.

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
Best Answer

Answer by Symphony · Sep 26, 2014 at 03:25 AM

Hi

You need to access your second script within your MissileFireSystem script. An easy way would be to make the bool static then you can just access it with something like

scriptname.scriptvariable

In your case secondscript.weaponSafe *This only works with static variable..and could become a problem if you need to access that bool anywhere else

The other way would be to something like

Access the second script by making a variable for it ex: private secondscript

Then assign it to the appropriate script ex: secondscript = Find the gameObject

Then you can just access it variables like before secondscript.weaponSafe

Note: I'm not a programmer at ALL, i'm still learning myself. So I invite anyone to correct me if i'm wrong...not trying to lead anyone astray

Hope that helps

Comment
Add comment · Show 2 · 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 SuperPurpleByte · Sep 26, 2014 at 03:14 PM 0
Share

Thanks ! Helps a ton

avatar image Symphony · Sep 26, 2014 at 03:31 PM 0
Share

Not a problem, happy to help

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

26 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

Related Questions

Unity UI Button Switch Bool? 2 Answers

Add a bool to animator & activate by key press 1 Answer

Unable to set boolean to true 1 Answer

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

c# Ignoring conditional statement? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges