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!
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;
Works perfectly! Thank you, this whole operators in parentheses thing is throwing me off and taking some getting used to haha.