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 Slingo_the_cat · May 14, 2015 at 04:59 PM · c#javascriptvariablefunctionc# to javascript

Lower player's health from separate script.

So basically, i want to make it so that when the enemy object touches the player object, it will lower the player's health. The problem is that, the enemyAI script is written in javascript and the health bar script is written in c#. I could either get the enemy script to modify a variable or call a function in the health bar script (which would modify the variable value anyway). How would i go about doing this? Let me know if you need to see my scripts or anything.

Thanks in advance-

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · May 14, 2015 at 05:20 PM

There are a number of answers on this site and on the forums and on google detailing how to access one variable from one language in another. Those are pretty easy to find if you search.

That being said, though, if you want to avoid headaches in the long run, use only one scripting language.

Comment
Add comment · 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
0

Answer by InsertFunnyUsernameHere · May 14, 2015 at 05:29 PM

Why would you even write scripts in Javascript and C# at the same time? That doesn't make sense unless you're working in a group... Anyways if you want the player to loose health by simply touching the enemy then you may want to use OnCollisionStay or OnCollisionEnter functions and access the collider's tag to check if it's a player.

For example

       public class HealthScript :MonoBehaviour 
     {  
  float health
 {
 set
 {
 health=value;
 if(health<0)
 Die();
 }
 }
   public static void ReceiveDamage(float damage) {
          health-=damage; }
          
          voidDie() { Destroy(this); }
          
          }
     
 
 
 
 
 
         public class Enemy :MonoBehavior
         {
         
         float damage;
         
         OnCollisionStay(Collision col)
         {
         if(col.collider.gameObject.tag=="player")
         {
          HealthScript.ReceiveDamage(damage);
         }
         }
         }
 
 
 
 
 
 




Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

What is this C# code in javascript 0 Answers

GetComponent, What is it ? 1 Answer

When issuing to print a private variable from the script, the script prints all the variables attached to objects using the same script instead of the specific object. How do I fix this? 3 Answers

summing up items price in runtime 1 Answer

Changing Value in JavaScript from C# 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