Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Dec 18, 2014 at 06:24 AM by fafase for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Ochreous · Dec 18, 2014 at 04:39 AM · c#transformfind

C# The call is ambiguous between the following methods or properties

I'm getting an error from the console saying "The call is ambiguous between the following methods or properties" and points me to this line of code. I'm not entirely sure what is wrong with this code since I've used vector3s with vector2s in other parts of my script with no issues. What exactly is wrong this code?

 transform.Find("gameobject1").localPosition = transform.Find("gameobject2").localPosition + new Vector2(Random.Range(0.5f, 0.75f), 0.0f);

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by InGameDev · Dec 18, 2014 at 05:09 AM

use this transform.Find("gameobject1").localPosition = transform.Find("gameobject2").localPosition + new Vector3(Random.Range(0.5f, 0.75f), 0.0f,0);

Comment
Add comment · Show 2 · 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 Bunny83 · Dec 18, 2014 at 06:14 AM 3
Share

You don't even need the "0" as the Vector3 constructor has an overload with only two parameters (x and y).

@DangerousBeans:
The problem here is that Vector2 has two implicit casting operators defined. So a Vector2 can implicitly converted into a Vector3 and a Vector3 into a Vector2 if necessary.

The ambiguity actually comes from the "+" operator. There is one for Vector2 that takes two Vector2 parameters and one for Vector3 that takes two Vector3 parameters.

Since you have one Vector3 and one Vector2 parameters the compiler has to look for an operator that works with those parameters. However, there is none. So it has to look for an implicit cast if it can cast one of the parameters into a type that one of the "+"operators can take.

The problem is that the Vector2 can be casted into a Vector3 and it will use the Vector3 "+"operator, but it's also possible to implicitly cast the Vector3 into a Vector2 and use the Vector2 operator. Both implicit casts are possible. Since the compiler has two ways to solve this issue it throws this error.

avatar image InGameDev · Dec 18, 2014 at 07:15 AM 0
Share

yup....it will also work

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C# GameObjectList not Setting Parent 0 Answers

C# Smoothing Out transform.Translate 4 Answers

C# Transform Issues 1 Answer

C# GUI.Button Transform.Position 1 Answer

C# Need Help Refining Ricochet Script 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