The question is answered, right answer was accepted
Operator `+' cannot be applied to operands of type `UnityEngine.Vector3' and `float'
Simple but out of my head, (Much noob)
What's with this error, I know what it means, but I don't know where I am wrong:
spriteBound = gameObject.GetComponent<SpriteRenderer>().sprite.bounds;
vector3 upperLeft = transform.position - transform.right * spriteBound.extents.x + transform.up + spriteBound.extents.y;
Thanks
Answer by 5c4r3cr0w · Dec 09, 2016 at 09:55 AM
Error message is simply suggesting that you are trying to add Vector3 or and float.
'+' operator can only be applied if there are similar data types at both sides of it. Here transform.position and transform.up are vector3. and spriteBound.extents.x and spriteBound.extents.y are float values.
Although it would probably not make much functional sense for most of us, the add operation between a Vector3 and a float could be defined as a new Vector3(v.x + f, v.Y + f, v.z + f) much in the same way multiplication with a float is new Vector3(v.x f, v.y f, v.z * f).
Answer by RobAnthem · Dec 09, 2016 at 10:50 AM
You can't apply single vector changes to a whole vector3, you have to make it 3 seperate equations if you want to define X, Y, and Z, seperately, even if you define Vector3 as a new vector, you'll need to define the X, Y, and Z individually in the constructor.
Answer by KazYamof · Dec 09, 2016 at 09:57 AM
That means you can't sum a Vector with a constant value, it makes no sense. You can scale a vector by a constant, so a Vector3.one * 5 = Vector3(5,5,5). I don't know what are you trying to achieve, but fix your operation:
This way you scale the transform.right by the sum of x + up + y..
Vector3 upperLeft = transform.position - transform.right * (spriteBound.extents.x + transform.up + spriteBound.extents.y);
This is the syntax, but the semanthics is up to you.
Follow this Question
Related Questions
Array index out of range(C#) 1 Answer
Framing multiple objects from a list along y axis only? 0 Answers
Trying to transform my character's local position on a GetKey. 0 Answers
NullPointException Object not found, caused by a variable not accepting value? 0 Answers
3D Pong Clone: Set position of a Rigidbody, or change how a speed vector is verified? 1 Answer