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 11, 2014 at 12:07 PM by flamy for the following reason:

Duplicate Question

avatar image
0
Question by Entyro · Apr 11, 2014 at 11:58 AM · c#javascriptscrip

Call JavaScript from c# Help!

Hi!

I have an inventory script and a pick up script. I'm using it for picking up batteries around my evel.

The problem I have is when I've picked up a battery and want to use it, it needs to call a function from a JavaScript file that I'm using for my flashlight. Do any of you guys know how to do that?

Note! I'm using this part of code in a JavaScript when I'm calling the flashlight function "Flashlight.AlterEnergy(batteryPower);"

Inventory script:

 using UnityEngine;
 using System.Collections;
 
 public class Inventory : MonoBehaviour {
     //GUI Skin
     public GUISkin InvSkin;
     //Slots
     public static string slot1 = "Empty 1";
     public static string slot2 = "Empty 2";
     public static string slot3 = "Empty 3";
     public static string currentItem = "None";
     //Other Vars
     private bool isenabled = false;
     private int messageint = 0;
     private string messagetext = "";
     private bool remove = false;
 
 
     void Update()
     {
        
             if (messageint >= 0)
             {
                 messageint--;
             }
 
         if (Input.GetKeyDown(KeyCode.Alpha1))
         {
             currentItem = slot1;
             messageint = 100;
             messagetext = slot1 + " Used";
             ActivateItems(currentItem);;
         }
         else if (Input.GetKeyDown(KeyCode.Alpha2))
         {
             currentItem = slot2;
             messageint = 100;
             messagetext = slot2 + " Used";
             ActivateItems(currentItem);
         }
         else if (Input.GetKeyDown(KeyCode.Alpha3))
         {
             currentItem = slot3;
             messageint = 100;
             messagetext = slot3 + " Used";
             ActivateItems(currentItem);
         }
         if (Input.GetKeyDown(KeyCode.Tab))
         {
             if (isenabled)
             {
                 isenabled = false;
             }
             else if (!isenabled)
             {
                 isenabled = true;
             }
         }
     }
 
     void OnGUI()
     {
         GUI.skin = InvSkin;
         if (messageint > 1)
         {
             GUI.Label(new Rect(Screen.width/2-50, Screen.height/2-55, 120, 50),messagetext);
         }
         if (isenabled)
         {
             if (GUI.Button(new Rect(Screen.width / 2 - 170, Screen.height / 2 + 390, 100, 30), slot1))
             {
                 if (!remove)
                 {
                     currentItem = slot1;
                     messageint = 100;
                     messagetext = slot1 + " Used";
                     ActivateItems(currentItem);
                     slot1 = "Empty 1";
                 }
                 else
                 {
                     messageint = 100;
                     messagetext = slot1 + " Removed";
                     slot1 = "Empty 1";
                     remove = false;
                 }
             }
             if (GUI.Button(new Rect(Screen.width / 2 - 40, Screen.height / 2 + 390, 100, 30), slot2))
             {
                 if (!remove)
                 {
                     currentItem = slot2;
                     messageint = 100;
                     messagetext = slot2 + " Used";
                     ActivateItems(currentItem);
                     slot2 = "Empty 2";
                 }
                 else
                 {
                     messageint = 100;
                     messagetext = slot2 + " Removed";
                     slot2 = "Empty 2";
                     remove = false;
                 }
             }
             if (GUI.Button(new Rect(Screen.width / 2 +90, Screen.height / 2 + 390, 100, 30), slot3))
             {
                 if (!remove)
                 {
                     currentItem = slot3;
                     messageint = 100;
                     messagetext = slot3 + " Used";
                     ActivateItems(currentItem);
                     slot3 = "Empty 3";
                 }
                 else
                 {
                     messageint = 100;
                     messagetext = slot3 + " Removed";
                     slot3 = "Empty 3";
                     remove = false;
                 }
             }
             if (remove)
             {
                 if (GUI.Button(new Rect(Screen.width / 2 + 300, Screen.height / 2 + 390, 100, 30), "Stop"))
                 {
                     remove = false;
                 }
             }
             else if (!remove)
             {
                 if (GUI.Button(new Rect(Screen.width / 2 + 300, Screen.height / 2 + 390, 100, 30), "Remove"))
                 {
                     remove = true;
                 }
             }
         }
     }
     void ActivateItems(string slot)
     {
        
     }
     
 }
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

21 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 avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Tutorial level 2 Answers

Javascript code not working plz help 1 Answer

In Game Animation 2 Answers

GUI Problem 2 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