- Home /
How to make a C# script to JavaScript
I'm trying to make a collider code that uses another script to function. I have the code in c# but the problem with the script is that the script I'm trying to reference to is a javascript. So, I just want to convert the script to java, to make lifew easier. I just need a simple translation for :
void OnTriggerEnter(Collider otherObj)
{
if(damageOnEnter)
{
if(otherObj.GetComponent<PlayerHealth>() != null)
{
otherObj.GetComponent<PlayerHealth>().DamagePlayer(damage);
}
}
}
All I have so far is:
function OnTriggerEnter(Collider otherObj)
{
if(damageOnEnter)
{
if(otherObj.GetComponent<PlayerHealth>() != null)
{
otherObj.GetComponent<PlayerHealth>().DamagePlayer(damage);
}
}
}
Try this: http://florentpoujol.fr/content/unity3d/csharptounityscript/
Although I think you just need to set the parameter of the OnTriggerEnter function to something like:
function OnTriggerEnter(otherObj : Collider)
Also check the docs on GetComponent (you can set the code examples in JavaScript.
Answer by Landern · Jun 11, 2014 at 02:08 PM
function OnTriggerEnter(otherObj : Collider)
{
if(damageOnEnter)
{
// try not to call getcomponent multiple times if you can help it
PlayerHealth ph = otherObj.GetComponent.<PlayerHealth>();
if(ph)
{
ph.DamagePlayer(damage);
}
}
}
Your answer
Follow this Question
Related Questions
Script translation 2 Answers
How to use Android Dual Joysticks? 1 Answer
Using PlayerPrefs to transfer variables from Javascript to C# 1 Answer
Can someone convert this C# script to javascript 1 Answer
My Health Script Won't work in C# 1 Answer