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 /
This question was closed Apr 15, 2015 at 08:49 AM by EggQuiz857 for the following reason:

Other

avatar image
0
Question by EggQuiz857 · Apr 14, 2015 at 11:57 PM · booleancacheaccessing from any scriptvarible

Need help accsesing a scripts variable alfter getting the script cached.

Here is my code

 #pragma strict
 
 var Running = false;
 
     function Start () {
 
     }
 
     function Update () {
 
     }

This is the code that I want to change the variable Running to true.

 #pragma strict
 
 var CarScript : UnityEngine.MonoBehaviour;
 
     function Car () {
         
     }
 

This is the code to change the variable. So what the var CarScript : UnityEngine.MonoBehaviour; dose is gets the gameobject and its script.

So now I have the script cached now I need to accses the variable.

I tried to have It like Carscript.Running = true; but it didn't work.

any help?

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

  • Sort: 
avatar image
0

Answer by toddisarockstar · Apr 15, 2015 at 12:41 AM

it took me awhile to figure this out too. i couldnt get responses and finally figured it out myself. anyways, depending on whether you are building for web,flash or standalone there are simpler ways of accessing other script, but here is the way i found to work with all. its kinda weird but always works. if you want to declair your variable above Update it looks like this:

  //get an object with the desired script attached!!!
 
  var car:GameObject;
  car = gameObject.Find("car");
 
 // assign the variable to expect the script component you are looking for!!!
 
  var cs: nameofcarscript = car.GetComponent(nameofcarscript);
 
 // now we declaired the component variable type so now we can actually assign it to the car
 
 cs = car.GetComponent(nameofcarscript);
  
      function Car () {
 
    cs.goreallyfast=true;
          
      }
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 EggQuiz857 · Apr 15, 2015 at 01:01 AM 0
Share
 #pragma strict
 var CarerCar : GameObject;
 var CarScript = CarerCar.GetComponent(Car);
 CarerCar = gameObject.Find("Car");
 
     function Car () {
     CarScript.Running = true;
     }

This is what I have done but I get an error at the CarerCar = gameObject.Find("Car");.

The error says. Assets/CarereChoser.js(3,38): BCE0023: No appropriate version of 'UnityEngin.GameObject.GetComponent' for the argument list '(function(): void)' was found

This game is a tycoon game btw and not a racing game. to shed more light on this. the game is were you chose what career you want to do and live in a real life economic situation trying not to lose money.

avatar image toddisarockstar · Apr 18, 2015 at 03:07 AM 0
Share

sorry for delay, if you havent allready got it, switch the 2 lines like this so the second variable knows what you are talking about:

  #pragma strict
  var CarerCar : GameObject;
  CarerCar = gameObject.Find("Car");
  var CarScript = CarerCar.GetComponent("Car");
 
  
      function Car () {
      CarScript.Running = true;
      }


if you want to try it this way put quotes around "Car" if thats also the name of your script. that will get rid of the error. this way might work for a webplayer but pry idk about flash or standalone

Follow this Question

Answers Answers and Comments

18 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

Related Questions

lock and key mechanic: how to use variables across scripts 2 Answers

Variable not changing when you get a reference from another script 1 Answer

Toggle between first and third person - how do I toggle back? 1 Answer

Problem with looking to target OnMouseEnter 1 Answer

!!!BCE0044: expecting EOF, found 'else'.!!!!!! 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