- Home /
How to make this line work in C#?
I have this codeline in JS and works fine:
JS: var tempDistance = Vector3.Distance (TargetPosition, hit.point) - 0.28;
TargetPosition is a Vector3 position of the target, and hit.point is the position of the RayCastHit.
C#: Vector3 tempDistance = Vector3.Distance(TargetPosition, hit.point) - 0.28;
But this is not working in C#. why? I got an error: error CS0029: Cannot implicitly convert type float' to
UnityEngine.Vector3'
How can fix it? It is very important for me.
Answer by Meltdown · Aug 12, 2012 at 08:47 PM
You're trying to assign a float to a Vector3, which won't work. Vector3.Distance returns a float. So it needs to be...
float tempDistance = Vector3.Distance(TargetPosition, hit.point) - 0.28;
Oh, how stupid am I... thanks a lot!! and i also needed to correct the double to -0.28f;
Your answer
Follow this Question
Related Questions
java to C# conversion 1 Answer
Can someone help me translate this to c#? 1 Answer
About "translating" js into C# 1 Answer
Help converting this to C# - a few issues 3 Answers
C# to java translation 2 Answers