-1
\$\begingroup\$

When starting the game, I make the size of the object random. And when I start the game, how can I check if the object's size is smaller than x-1, y-1, and the z doesn't matter. When I try something I get this error: 'non-invocable member 'Vector3' cannot be used like a method.'

Here is the if statement that the error is in:

if(transform.localScale < Vector3(1, 1, 1))
{

}

I also forgot to mention that the if statement is at the end of the start method.

\$\endgroup\$
4
  • \$\begingroup\$ This error message is telling you that you're trying to "call" Vector3 like it's a function. It looks like you meant to construct a new Vector3, but you're missing a "new" keyword for that. But more importantly, there's no less-than/greater-than relation defined on vectors, so it's unclear what you want this code to do. If localScale is (0.9, 1.1, 1), should that return true because the x is smaller, or false because y is bigger, or true because the volume 0.9*1.1*1=0.99 is less than the volume 1*1*1=1? Clarify your desired logic first, then we can help you translate that logic to correct code \$\endgroup\$
    – DMGregory
    Aug 29 '21 at 11:40
  • \$\begingroup\$ what I meant was to get the object's size, and check if its size is smaller than 1 on each axis and if it is, then destroy that object. My approach to doing it the way I did was probably wrong and a bit confusing. \$\endgroup\$
    – DavidA_
    Aug 29 '21 at 11:46
  • \$\begingroup\$ So, presumably you tried the obvious thing of if (transform.localScale.x < 1 && transform.localScale.y < 1), right? Did anything go wrong when you did that? \$\endgroup\$
    – DMGregory
    Aug 29 '21 at 11:48
  • \$\begingroup\$ I actually just tried that right now and it worked. I didn't think of doing that. Thanks! \$\endgroup\$
    – DavidA_
    Aug 29 '21 at 11:55
0
\$\begingroup\$

I used if(transform.localScale.x < 1 && transform.localScale.y < 1) instead of transform.localScale < Vector3(1, 1, 1) Which seemed to work perfectly.

\$\endgroup\$
0
\$\begingroup\$

Vectors can not be compared directly, but you can compare their .magnitude.

Or alternatively, if you always set the x and y component of those scales to the same, you can just compare one of those. This would be slightly faster, because you don't need to calculate the magnitudes.

\$\endgroup\$
4
  • \$\begingroup\$ theres no need to do that. local scale worked just perfectly and I didn't want to use vectors, that was a slight mistake. \$\endgroup\$
    – DavidA_
    Aug 29 '21 at 13:28
  • \$\begingroup\$ @DavidA_ localScale is a vector. \$\endgroup\$
    – Philipp
    Aug 29 '21 at 15:50
  • \$\begingroup\$ I meant that I didn't need to use vector3 or vector2 \$\endgroup\$
    – DavidA_
    Aug 29 '21 at 16:04
  • \$\begingroup\$ @DavidA_ localScale is a Vector3 😉 \$\endgroup\$
    – DMGregory
    Sep 1 '21 at 15:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .