- Home /
This question was
closed Apr 11, 2014 at 12:07 PM by
flamy for the following reason:
Duplicate Question
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
Follow this Question
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