Raycast variable type in C#?
So i am trying to translate all my JS scripts to C# by using a converter and I understand that I will need to change a few errors that come up. In this most recent script, I am unsure of naming one of the variables I used in JS called "hit" Here is the code. I am having trouble because I don't think its supposed to be RaycastHit.
JS function with hit. This is the only time hit is used
function Update()
{
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
{
C# attempt. I assume RaycastHit is not a variable type or I named it incorrectly.
void Update (){
RaycastHit hit;
fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
{
Answer by Silvermurk · Jun 05, 2016 at 11:57 PM
You are missing a RaycastHit variable:) And i allweys add debug.drawray to see how it actually behaves - helps alot ) Try this as an example:
Ray rayOrigin = Camera.main.ScreenPointToRay(Input.mousePosition); //Ray from camera to mouseclick position
RaycastHit hitInfo; // info of object hit by ray (THIS IS YOUR VARIABLE!)
if(Physics.Raycast(rayOrigin,out hitInfo, distance,9))
{
Debug.DrawLine(rayOrigin.direction, hitInfo.point,Color.red);
}
Your answer
Follow this Question
Related Questions
How can I change this java to C# 2 Answers
JavaScript to C# 1 Answer
Convert Js yo C# 1 Answer
Make a Raycast pass through a layer? 0 Answers
Convert Java to C# 2 Answers