Hi sorry for bothering, but I can’t handle with this on my own cause I total null in JS.
Can someone please help me to transform this JS to the same but C# script.
var hasCollided : boolean = false;
var labelText : String = "";
function OnGUI()
{
if (hasCollided ==true)
{
GUI.Box(Rect(140,Screen.height-50,Screen.width-300,120),(labelText));
}
}
function OnTriggerEnter(c:Collider)
{
if(c.gameObject.tag =="Player")
{
hasCollided = true;
labelText = "Hit E to pick up the key!";
}
}
function OnTriggerExit( other : Collider ){
hasCollided = false;
}
One more question can I trust this site: Convert unity javascript (unityscript) to C#
It’s some kind of converter of script, someone test it already?
Can you ‘trust’ it? Well, you should always test code that’s been generated by anything… or heck, code you’ve written. Just test everything. I’m not sure where ‘trust’ comes into it.
Except for a few relatively obscure abilities of the languages converting between them is pretty straightforward, so it should be pretty easy for an automated convertor to work.
You really should try converting it yourself. It’s a great exercise in learning the language syntax and the differences between US and C#.
Give it a shot first, and if you have errors that won’t let you build, and you can’t figure them out, then come back and ask and I’ll gladly help.
Just tried to use this converted script, it should to show a string when camera rayCasting on Colider
But it didn’t work.
using UnityEngine;
using System.Collections;
public class ActButtonString : MonoBehaviour {
bool hasCollided = false;
string labelText;
void OnGUI()
{
if (hasCollided == true)
{
GUI.Box(new Rect(140, Screen.height - 50, Screen.width - 300, 120), (labelText));
}
}
void OnTriggerEnter(Collider c)
{
if (c.gameObject.tag == "Player")
{
hasCollided = true;
labelText = "Hit E to pick up the key!";
}
}
void OnTriggerExit(Collider other)
{
hasCollided = false;
}
[RPC]
void Test() { }
}