Type of conditional expression cannot be determined because ‘UnityEngine.Vector’ and ‘UnityEngine.Vector2’ implicitly convert to one another (CS0172).
I’m hardly even a beginner when it comes to programming, but the funny thing is I managed to replicate this project/script a couple months ago and still have it saved (and it works just fine).
So to clarify, I have a problem with a script that I had no problem with before (and still have and can run it), but I want to know/learn how I can fix the current problem.
I glanced through the source code (link to the Github below for anyone else), but I can’t actually determine why it is throwing an error. Is there somewhere I can download the completed project?
All right, I expanded it as suggested by GroZZleR, and now the code runs successfully builds without error.
… But it doesn’t function as it should, as in the player object is not colliding/detecting the obstacle.
But, that’s just fine. I’m just very relieved I wasn’t overlooking something simple or what not. I’ll just start over from scratch and maybe post here if I run into some more problems.
Thanks very much for your help, Ryiah and GroZZleR. You guys helped a lot more than you may believe.
I generally suggest avoiding the ternary operator for all but the most simple lines. It’s confusing to keep track of the logic. That said, I’m puzzled why it didn’t work.
I have encountered similar errors in the past due to the nature of implicit casting between Vector3 and Vector2. This line
myVector3 + myVector2
will throw a compiler error because the compiler can’t figure out if I meant Vector3 addition or Vector2 addition. It might be something similar.
Ah, all right. Thanks for your input as well, BoredMormon. Its a relief to know vastly more competent people than myself are also puzzled at this bizarre occurrence.
Yeah, the implicit cast is annoying. By proper programming rules a cast from a Vector3 to a Vector2 should be explicit, as you are losing information. It’s one of Unity’s ‘shortcuts’ that causes hassles.
I literally just discovered you could simply cast a vector2 to a vector3 yesterday. ;). I was working on some ui stuff and was doing it the long way (new vector2(v1.x,v1.y,0; ). One the other guys asked why I wasn’t just casting it. And then learning happened!