Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Daniel77 · Aug 02, 2011 at 05:51 PM · c#vector3functionprivate

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AVividLight · Aug 02, 2011 at 06:17 PM 0
Share

Why do you want it to be in JavaScript?

avatar image Daniel77 · Aug 02, 2011 at 06:35 PM 0
Share

Because that is the language i understand the most (Unityscript). Still have heaps to learn though. :)

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by aldonaletto · Aug 02, 2011 at 06:10 PM

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.
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Daniel77 · Aug 02, 2011 at 06:37 PM 0
Share

Yeah you code worked well, except it through up an error at the 'as Vector2' it didn't like the 'as' part so i changed it to:

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

Thanks for the help.

avatar image
0

Answer by Meltdown · Aug 02, 2011 at 06:09 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Daniel77 · Aug 02, 2011 at 06:35 PM 0
Share

Thanks for the help. :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Why inpector keeps methods assigned when changed from public to private 2 Answers

Need help converting js to C# 4 Answers

C# Return Type Error? 1 Answer

calling c# function from a js file.. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges