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
1
Question by $$anonymous$$ · Aug 17, 2013 at 02:58 AM · valueget

how to get value from other script?

I have 2 Script :

  1. EnemyAI [this C#]

  2. EnemyHealt [this JavaScript]

I want to get value CurrentHealt from EnemyHealt to EnemyAI. How to do that?

NB: Sorry for my bad english.

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

Answer by VioKyma · Aug 17, 2013 at 03:13 AM

You will have problems going from UnityScript (JavaScript) to C# because they are actually stored in different projects. I would highly recommend using one or the other unless you have no other choice.

Basically, you want to find the object, then reference the script and value. For example if the script was on the same object:

 EnemyHealth enemyHealth = GetComponent<EnemyHealth>();
 // Get current health
 enemyHealth.CurrentHealth;

Or if they are on different objects:

 GameObject enemy = GameObject.Find("Enemy");
 EnemyHealth enemyHealth = enemy.GetComponent<EnemyHealth>();
 // Get current health
 enemyHealth.CurrentHealth;
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 $$anonymous$$ · Aug 17, 2013 at 03:38 AM 0
Share

so, that is imposible to do. O$$anonymous$$ thank you very much.

avatar image VioKyma · Sep 03, 2013 at 01:58 PM 0
Share

Not impossible, Unity documentation states that:

A common example is where a UnityScript file needs to reference a class defined in a C# file. You can achieve this by placing the C# file inside a Plugins folder and the UnityScript file in a non-special folder. If you don't do this, you will get an error saying the C# class cannot be found.

It is fiddly but can be done. You can find more on it here (and in the rest of that section): https://docs.unity3d.com/$$anonymous$$anual/ScriptCompileOrderFolders.html

avatar image tolfer · Jul 04, 2017 at 09:21 AM 0
Share

Awesome, I was waste my time with this problem and your sollution solve it. Thank You

avatar image rAsor8888 · Jul 03, 2021 at 12:44 AM 0
Share

This did not work for me, I have posted another link to a solution that does

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

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Using Static Value? 1 Answer

How to get a value set by another script? 0 Answers

Helper properties get reference to player position 2 Answers

How to get the index value on prefab button runtime by clicking on prefab 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