• 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 LinkUpGames · May 28, 2016 at 05:18 AM · c#raycastvector3

Operator '+=' is ambiguous on operands of type 'Vector3' and 'Vector2'?

Hey so I am trying to add spread to the RayCast script I currently have for my weapon in my game. I found a script that was in JS that I attempted to reorient more to my needs and I run into the above error. The following is the portion of the script causing the error: Vector3 pos = new Vector3(Screen.width 0.5f, Screen.height 0.5f, Camera.main.nearClipPlane); pos += Random.insideUnitCircle * spreadFactor; Ray ray = Camera.main.ScreenPointToRay(pos); If I change the '+=' to just '=' it works but the spread is massive and doesn't seem to be randomized at all. Any help would be very appreciated!

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 Deathtruth · May 28, 2016 at 08:23 AM

Explicitly cast Random.insideUnitCircle to a Vector3. To avoid ambiguity.

Eg. pos += (Vector3)Random.insideUnitCircle * spreadFactor;

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 LinkUpGames · May 29, 2016 at 02:14 AM 0
Share

Works perfectly! Thank you, this whole operators in parentheses thing is throwing me off and taking some getting used to haha.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I move an object in the direction another object is facing. 1 Answer

Help with raycast for for wall detection 1 Answer

Why isnt my raycast hitting the floor? 0 Answers

how to check if an object is betwen enemy and player 1 Answer

Rotated object raycasting in wrong directions!!? 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges