- Home /
Converting Variable to C#
Could someone Translate this line of code to C# for me please?
var hitRotation = Quaternion.FromToRotation(Vector3.up, Hit.normal);
Thanks!
I'm not sure, but :
Vector3 up = new Vector3(0,0,0);
Vector3 hit = new Vector3(0,0,0);
Quaternion hitRotation = new Quaternion(0,0,0,0);
hitRotation.SetFromToRotation(up, hit);
Just so you know, Vector3.up is a specific vector that points straight up, not a new vector called "up", with the values of (0,1,0). (Vector3.forward, back, down, left, right are all similarly defined vectors).
Answer by moonstruck · Jul 26, 2013 at 11:57 AM
It is a valid C# code line (if you have variable Hit
defined).
exactly, but if you want to explicitly declare the variable type (ins$$anonymous$$d of type inference), it should look like this:
Quaternion hitRotation = Quaternion.FromToRotation(Vector3.up, Hit.normal);
The variable "Hit" should be of type "RaycastHit".
Okay I think its working if you put Quaternion in front of it thank you...just as a small question I know it's a different question but can someone tell me what variable type it is hier:
var DirectionRay = transform.TransformDirection (Vector3.forward);
It would really help me out :)
Great thank you all very much! I have to get used to moving from Java to C# :)
The best way to figure this out yourself is to look up the function in unity docs. Here's the function you just asked about. $$anonymous$$ake sure that the reference language is set to c# in the drop down box. At the top of the page it has this line:
Vector3 TransformDirection(Vector3 direction)
Which explicitly says that it takes in a Vector3 for direction and outputs a Vector3.
Your answer
Follow this Question
Related Questions
java to C# conversion 1 Answer
js conversion to c#. no errors but still not working 1 Answer
Help with conversion from javascript to c# 3 Answers
Multiple Cars not working 1 Answer
Translate C# into Js 1 Answer