I’m new to Unity and although in general I’m very excited about how simple it is to do many visually appealing things, some basic things seem to require more effort when writing code. I’d be interested to here some comments on these questions:
Why C# doesn’t allow for transform.x += 1? Why is x read only? Writing transform.position = new Vector3(targetXpos+1, transform.position.y, transform.position.z) feels overlengthy and even computationally ineffective. JavaScript doesn’t require initializing a new Vector3 every time (at least not in the code you write), but I’ve understood that C# is a better choice in general due to at least being better integrated.
Being used to just writing trace(“”); with AS3 Debug.Log is quite a long thing to always write. Of course I can put a shorter function for doing that, but then I need to put it in every single script where I want to do quick debuggin. I know it’s just about a few characters but this is needed very often, so I’m asking if there is a shorter way of doing this?
What is the neatest way to access some general data or functions used by a lot of objects? I can’t just use some Reg.someVar to get some variable from a static class like eg. in ActionScript right? What’s the shortest way I can do this with Unity? There is probably any way a more convenient way of accessing variables than GameObject.Find(“Reg”).GetComponent(VarContainer).someVar, right?
Slightly related, as this is also about minimizing recurring efforts, I’m wondering about why the default plane is 10x10. I found some topics about that, but it still feels weird that 10x10 is the default, and even the only option given. Some say it’s just for prototyping anyway, but I why basic planes couldn’t be used as they are even for other purposes than just prototyping? And even for prototyping, why would the 10x10 be better for that? I suppose it’s easier to perceive its size and location while editing, but is that it?
Because normally you do not set just a part of a vector, you set the entire vector. Since it’s a property, there are additional side-effects of setting the values. Setting them individually will require 3 times as much work, and is way more computationally ineffective. UnityScript does a lot of stuff for you in the background, so while it might be easier to use for someone unfamiliar with both languages, it is also easier to do something “computationally ineffective” without knowing it.
9 character vs. 5 doesn’t seem that big of a difference, but if you really, really want something smaller, you could create an extension method to the string class. (you don’t have to put it in each class). Something like this:
public static class MyExtensions
{
public static void Log(this String str)
{
Debug.Log(str);
}
}
And then you could just do stuff like this:
“Send me to the console”.Log();
Put them in a static class, like you did in AS.
[/quote]
Okay, I kind of anticipating that there really has to be more going on under the hood, since otherwise it wouldn’t really make sense. Still, I suppose it’s effective to state
transform.x += 1;
to make the whole Vector3 setting statement, if you only need to change the location on one axis? So if one knows this, transform.x += 1 wouldn’t be any less efficient? Well, one can make helper functions for this, if needed, so this isn’t that big a deal.
Okay, thanks, I’ll keep that in mind.
Hah. Why didn’t I just try that earlier? I just somehow thought it wouldn’t work like that.
The 10x10 plane I’m still a bit curious about, but it’s of course not critical, since it’s not a big deal to change it to a 1x1 plane.