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 Feb 15, 2015 at 05:43 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by MerlinsMaster · Feb 15, 2015 at 10:51 AM · getcomponent

Having trouble calling a variable from another script

Hey Guys,

In my scene, I have a game object "SystemsManager" which controls all of the UI Texts for my spaceship, called "PlayerShip".

SystemsManager has a script "SystemsScript", which calls the variables from PlayerShip's script ("Ship")and displays the values with my UI Text objects. I got it working okay, but when I tried to call a variable from a second script attached to my PlayerShip, called "PlayerShipDamage", it wouldn't work.

     public class SystemsScript : MonoBehaviour 
     {
         public Text velocityText;
         public Text throttleText;
         public Text headingText;
         public Text fuelText;
         public Text playerHealthText;
             
         private Ship shipScript;
         private PlayerShipDamage playerDamage;
             
         // Use this for initialization
         void Start () 
         {
             GameObject Ship = GameObject.FindWithTag("Player");
             shipScript = Ship.GetComponent<Ship>();
         
             playerDamage = Ship.GetComponent<PlayerShipDamage>();
     
             velocityText.text = "Velocity: " + shipScript.currentVelocity.ToString("0.00") + "m/s";
             throttleText.text = "Throttle: " + shipScript.throttle + "%";
             headingText.text = "Heading: " + shipScript.heading.ToString("0") + "deg";

             playerHealthText.text = "Player Health: " playerDamage.playerHealth + "%";
             
         }



It works fine with the variables being called from the script Ship, but when I do the exact same thing with the script PlayerShipDamage, I get the following error:

Assets/Scripts/SystemsScript.cs(33,70): error CS1525: Unexpected symbol `playerDamage'

I've examined the code several times, and it should work, but it doesn't.

Can anyone let me know what I'm doing wrong?

Thanks.

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

Answer by meat5000 · Feb 15, 2015 at 10:51 AM

You are missing a +

Comment
Add comment · Show 4 · 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 persijn · Feb 15, 2015 at 10:57 AM 0
Share

playerHealthText.text = "Player Health: " + playerDamage.playerHealth + "%"

avatar image meat5000 ♦ · Feb 15, 2015 at 11:07 AM 0
Share

I figured at least he could work that bit out :)

avatar image MerlinsMaster · Feb 15, 2015 at 05:35 PM 0
Share

Great Ceaser's Ghost! How on earth did I miss that? I guess I've been staring at this thing for way too long.

Anyway, thanks, guys.

avatar image meat5000 ♦ · Feb 15, 2015 at 05:43 PM 1
Share

Totally! Sometimes its best to go and have a coffee. If feels like you are wasting time but you find you save a load after all :)

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Issues with trying to change a variable in another script 1 Answer

How to get the value of a boolean in game object to another Game object script. 1 Answer

I have problem with getcomponent 1 Answer

Order of object instantiation scripting issues 0 Answers

C# - Auto increment of Scenes through Collision 0 Answers


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