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 /
  • Help Room /
avatar image
0
Question by ScavengerH · Aug 28, 2016 at 05:17 PM · error messagestuck

Help me please i am stuck.

So this is the code , and the message i get is The call is ambiguous between the following methods or properties: UnityEngine.Vector2.operator +(UnityEngine.Vector2, UnityEngine.Vector2)' and UnityEngine.Vector3.operator +(UnityEngine.Vector3, UnityEngine.Vector3)'

using UnityEngine; using System.Collections;

public class ball : MonoBehaviour {

 private Paddle paddle;
 private Vector3 paddleToBallVector;
 private bool hasStared = false;
 // Use this for initialization
 void Start () {

 paddle = GameObject.FindObjectOfType<Paddle>();
 paddleToBallVector = this.transform.position - paddle.transform.position;
 print (paddleToBallVector);

 }
 
 // Update is called once per frame
 void Update () {
 if (!hasStared) {
     this.transform.position = paddle.transform.position + paddleToBallVector;
 }

     if (Input.GetMouseButtonDown(0)) {

     print ("Left mouse Clicked, Launch ball");
     hasStared = true;
     this.GetComponent<Rigidbody2D>().velocity = new Vector2 (3f, 7.5f);


 }
 }
 void OnCollisionEnter2D (Collision2D collision){

     //Ball does not trigger sound when brick is destroyed
     //Not 100% sure why, possibliy because there isnt a brick
     Vector2 tweak = new Vector2 (Random.Range(0f,0.2f), Random.Range(0f,0.2f));
     if ( hasStared) {
     GetComponent<AudioSource>().Play();
     GetComponent<Rigidbody>().velocity += tweak;

     }

 }
 }

console error: The call is ambiguous between the following methods or properties: UnityEngine.Vector2.operator +(UnityEngine.Vector2, UnityEngine.Vector2)' and UnityEngine.Vector3.operator +(UnityEngine.Vector3, UnityEngine.Vector3)'

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

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

Answer by TBruce · Aug 28, 2016 at 05:41 PM

In OnCollisionEnter2D() change this

 GetComponent<Rigidbody>().velocity += tweak;

to this

 GetComponent<Rigidbody2D>().velocity += tweak;

but instead may want to make the following changes to your class like so

 using UnityEngine;
 using System.Collections;
 
 public class ball : MonoBehaviour
 {
     private Paddle paddle;
     private Vector3 paddleToBallVector;
 
     private bool hasStared = false;
     
     private AudioSource audioSource;
     private Rigidbody2D rigidbody2D;
 
     // Use this for initialization
     void Start ()
     {
         paddle = GameObject.FindObjectOfType<Paddle>();
         paddleToBallVector = this.transform.position - paddle.transform.position;
         print (paddleToBallVector);
         
         audioSource = GetComponent<AudioSource>();
         rigidbody2D = GetComponent<Rigidbody2D>();
     }
 
     // Update is called once per frame
     void Update ()
     {
         if (!hasStared)
         {
             this.transform.position = paddle.transform.position + paddleToBallVector;
         }
         if (Input.GetMouseButtonDown(0))
         {
             print ("Left mouse Clicked, Launch ball");
             hasStared = true;
             rigidbody2D.velocity = new Vector2 (3f, 7.5f);
         }
     }
 
     void OnCollisionEnter2D (Collision2D collision)
     {
         //Ball does not trigger sound when brick is destroyed
         //Not 100% sure why, possibliy because there isnt a brick
         Vector2 tweak = new Vector2 (Random.Range(0f,0.2f), Random.Range(0f,0.2f));
         if ( hasStared)
         {
             audioSource.Play();
             rigidbody2D.velocity += tweak;
         }
     }
 }
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 ScavengerH · Aug 28, 2016 at 06:51 PM 0
Share

Omg, i feel really dumb, :( spent over 30 $$anonymous$$tues to try to fix the error and at the end i found it and yep that works, Thank you soo much

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

65 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why do i get an error ? please help i've stuck for 20 min 1 Answer

can someone help me solove this error ? please, wasted 35 mins 0 Answers

Why the Unity is not opening? 0 Answers

Someone help me please! I am really tired 1 Answer

I'm working on a newer version of Unity, so I cant really fix this API its simple but i just cant think 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