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 malekbakeer · Dec 10, 2013 at 09:51 AM · callanother script

Call boolean from another script

i want to call boolean and i cant ...

these are the scripts

Cube Script:

 public var RED : boolean = false;



and i want to make it true from this script

RED CAM Script:

 public var CubeScript : MonoScript;
 
 function Start ()
 {
     CubeScript(RED == true);
 }

so what can i do

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 VioKyma · Dec 10, 2013 at 11:14 AM 0
Share

When you put RED == true, it is perfor$$anonymous$$g a comparison.

I think you mean to use the below to assign the value: CubeScript.RED = true;

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by el-santia93 · Dec 10, 2013 at 10:44 AM

how bout you do this in your cube script have a function that that sets the Boolean true like this

 function SetTrue(){
     red=true;
 }

then call this function from your other script like this

 function Start(){
     GameObject.Find("Cube").SendMessage("SetTrue");//cube here being the gameobject that has the first script attached to it
 }
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 malekbakeer · Dec 10, 2013 at 11:33 AM 0
Share

its right but i am hiding other things

so i have this

 function Update ()
 {
     if (touch >= 4)
     {
         if (RED == true)
         {
             renderer.material.color = Color.red;
         }
     }
 }

so can u correct it

avatar image el-santia93 · Dec 10, 2013 at 01:53 PM 0
Share

i don't understand what you mean by correct it but here goes

     function Update ()
     {
     if (touch >= 4&&RED==true)
     {
     renderer.material.color = Color.red;
     }
     }
     
avatar image
0

Answer by Bunny83 · Dec 10, 2013 at 02:20 PM

First MonoScript is an editor class which can't be used at runtime. Also it represents the script file asset and not an instance of the class that might be defined in the script.

Next thing is you don't "call" variables. You can access variables. Specifically you can "set"/"write" a variable or "get"/"read" a variable. You can only call methods. This is where most of the confusion about your question comes from i guess.

Your redcam script might should look like this:

 public var cube : CubeScript;
  
 function Update ()
 {
     if (touch >= 4)
     {
         if (cube.RED)  // Since it's a boolean a comparison to true (==true) is again true so it's pointless
         {
             renderer.material.color = Color.red;
         }
     }
 }

Note: "CubeScript" is the name of your cube script and you have to drag the object which has this cube script onto the cube variable in the inspector of your redcam script.

However since we have no idea what's the purpose of all this we can't suggest better ways.

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 malekbakeer · Dec 10, 2013 at 04:02 PM 0
Share

ok now look at that

why when i build it it gives me an error

i'll give you all the scripts i need to make the boolean true from other scripts ... look

But i dont want to edit Cube.js i want to edit ((RED CA$$anonymous$$.js, BLUE CA$$anonymous$$.js)) alt text

and BLUE, RED Scripts that i want to make the boolean true;

alt text

red blue.png (57.8 kB)
cube.png (79.1 kB)
avatar image Bunny83 · Dec 10, 2013 at 07:46 PM 0
Share

This is a whole mess. It's still not really clear what those classes should do. Usually the class name should geve a hint what a class is good for.

However in your "blue" and "red" scripts you don't use the variable you declared at the top (cube) but the class itself (Cube).

You have to use:

     cube.RED = true;
     // or 
     cube.BLUE = true;

However your two scripts won't work at the same time. First "Start" is called just once when the game starts. When you change your "ONOFF" variable afterwards it won't do anything.

Next thing is you set the "ONOFF" variable to true before your check in Start, so the one that is initialized last will actually matter.

Can you explain what this is good for? Generally having two script with almost identical code is a good sign for a bad concept.

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

19 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

Related Questions

Call a Function when Object Created 2 Answers

GameObejct.Find using string variable for name 1 Answer

How to call a function from a script component on another object 1 Answer

OnControllerColliderHit function not called? [C#] 1 Answer

How to use the same script on different objects at the same time? 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