private Vector3 function?

Hi all,

I have this slice of code in C# that i am trying to convert to js and i am having not much luck.

 private Vector3 PiecePosition(Vector3 pos)
 {

 }

I have tried to convert it into a function in js like this.

private function PiecePosition (pos : Vector3) : Vector3
{

}

But now i have two other pieces of code that are throwing up errors and i think it might be because of that function i created.

This line of code has not been changed from the C# script.

activePiece.transform.position = PiecePosition((Vector2)piecePositions[activePiece.name]);

This line of code has been changed a bit.

C#

Vector3 dV = PiecePosition((Vector2)piecePositions[activePiece.name]) - activePiece.transform.position;

js

var dV : Vector3 = PiecePosition((Vector2), piecePositions[activePiece.name]) - activePiece.transform.position;

The error i am getting on the two lines of code is:

The best overload for the method ‘JigsawPuzzle.PiecePosition(UnityEngine.Vector3)’ is not compatible with the argument list ‘(System.Type, Object)’.

I think the problem lies in the code at the very top but i don’t know how to fix it.

Any help would be appreciated.

Thanks.

There are some problems with this line of code…

var dV : Vector3 = PiecePosition((Vector2), piecePositions[activePiece.name]) - activePiece.transform.position;

Firstly, your method PiecePosition, takes a single Vector 3 as an argument.
You are passing your method a Vector2, then an array of piecePositions.
So you are giving it two arguments, not one, and both arguments are of the incorrect type.

Secondly, you have no closing bracket at the end of the statement.

The function declaration is correct. The problem is the type casting in the problematic line. You should use:

  var dv: Vector3 = PiecePosition(piecePositions[activePiece.name] as Vector2) - activePiece.transform.position;

The PiecePosition function requires a Vector3 as argument, but I suppose the piecePositions is an array of Vector2, and Unity will extend it to Vector3 automatically.