Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 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.

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

Error : Animator has not been initialized. UnityEngine.Animator:SetBool(String, Boolean) 1 Answer

How can i reverse all the booleans in a method? 2 Answers

How would I make 1 bool true whilst making others false 1 Answer

How to schedule responses (based on player's input text) for text adventure game? 0 Answers

How to call array element that has bool value true 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