Question by
AhadKhan98 · Nov 10, 2015 at 06:13 AM ·
convertcodepage
Help converting from unityscript to c#
Hi. Here is a code which basically detects if an object is clicked by using the box colliders and then moves to the next level accordingly. I need help in converting this script to c#. Please help me out.
if (Input.GetMouseButtonDown (0)) {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition); //typical mouse click input
var hit:RaycastHit;
if (Physics.Raycast (ray, hit, 20)) {
if(hit.collider.name == "Level1Collider") //this is all of our code for triggering loading levels when a collider is clicked on
Application.LoadLevel("level1");
if(hit.collider.name == "Level2Collider")
Application.LoadLevel("level2");
if(hit.collider.name == "Level3Collider")
Application.LoadLevel("level3");
}
}
Comment
Best Answer
Answer by say_forever · Nov 10, 2015 at 06:49 AM
done
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //typical mouse click input
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 20))
{
if (hit.collider.name == "Level1Collider") //this is all of our code for triggering loading levels when a collider is clicked on
Application.LoadLevel("level1");
if (hit.collider.name == "Level2Collider")
Application.LoadLevel("level2");
if (hit.collider.name == "Level3Collider")
Application.LoadLevel("level3");
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612044549im_/https://answers.unity.com/themes/thub/images/avi.jpg)