- Home /
Question by
davidflynn2 · Oct 14, 2012 at 01:20 PM ·
c#
Convert js to c#
Could any one plz help me I need to convert this code over to c# so I can add it into the script I already have. I know c# but I an not full sure of the conversions from js to c#.
enter code herevar shield : GameObject;
var timer = 60;
var cooldown = 0;
function Update ()
{
if(Input.GetKey(KeyCode.S))
{
Shield();
}
}
function Shield ()
{
if(cooldown <= 0)
{
shield.active = true;
yield WaitForSeconds(60);
shield.active = false;
cooldown = 2;
}
else if (cooldown >1)
{
yield WaitForSeconds(10);
cooldown = 0;
}
}
Comment
Best Answer
Answer by Montraydavis · Oct 14, 2012 at 01:27 PM
You really don't have any code that is different from what c# would use . . .
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
float Timer ;
GameObject shield ;
float cool ;
function Update ()
{
if(Input.GetKey(KeyCode.S))
{
Shield();
}
}
void Shield ()
{
if(cooldown <= 0)
{
shield.active = true;
yield WaitForSeconds(60);
shield.active = false;
cooldown = 2;
}
else if (cooldown >1)
{
yield WaitForSeconds(10);
cooldown = 0;
}
}
}
PS: I am not able to test this code out, but, it's at least the basis for what you are asking . Fix any issues Unity3D might bring up, though your code is simple/straightforward enough that I didn't catch any errors.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Converting to C# 1 Answer
Mouse Look is over riding my controller 1 Answer
Why does my slide out menu not work when i translate from JS to C#? 1 Answer