Should I use my own code instead of other people's code?

Hi everyone,

I’ve been trying to get into Unity 3d but it seem it’s harder to teach yourself how to play a guitar.
I’ve been watching countless tutorial and example video still can’t get well with the Unity 3d tools and the scripting.

Let get to the point. So I want to make an object move and the the code I usually see is:

float S = Input.GetAxis ("Horizontal");

but I always has my own style and I use something like this:

if(Input == w)
objec.moveUp    // Sorry I forgot all the API code because I haven't use it for 1 month but I'm sure you understand my point.

Is it has conflict with performance or is it the same thing?

I just can’t learn Unity 3D well. I teach myself C# and solving a lot of hard problem and I can say that it’s still easier to get into compare to Unity 3D.

Sorry for my English. I’ve been inactive in using Unity 3D for almost 1-2 month and I forgot everything.
I want to build a habit that I can do it well instead of remember everything I’ve seen.

Your code doesn’t take analog joysticks into account. There’s no way to move a little bit up, you’re either moving full-speed or not moving at all. Even non-analog controllers get a little tweening from Unity, IIRC.

I can tweak that. I hope you get my point. It wasn’t the code but what I mean is are the other alternative code work the same? Or only Input.GetAxis (); will be need in all case scenario?

Performance doesn’t matter if you’re only doing it once or twice. That said those two code snippets are not the same thing.

Hard to say when it all depends of the other code you are comparing to which in your example did not even work

I know that it’s not going to work because I’m writing an Algorithm instead of a workable code!
If you get the point then you will be able to understand what I wanted to ask.

Maybe this thread can get me back to learn Unity 3D again. I’m not smart but at least I’m a try hard person.

An algorithm is workable code. The definition is literally a “process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer”. If your code isn’t working, it means your algorithm isn’t working.

string Name = Console.Readline();
int ConName = Convert.ToInt32(Name);

and

int Name = int.parse (Console.ReadLine());

Is it the same? and if not then why?

You’re using different functions.

http://stackoverflow.com/questions/199470/whats-the-main-difference-between-int-parse-and-convert-toint32

Again, now even if the code works your examples do not match. You are using parse in another and convert in another.

Algorithm is a problem solving step following by a flowchart. (Translated)

My algorithm should be work but the code snippet that I gave might not be but please try undertand it and get to the point…

I’m not the one having trouble understanding here.

If the result is what you want, it doesn’t matter how you got there.

1 Like

There is no point if you are trying to compare different functions which can be the same in the end and sometimes not. In some cases it does not matter, in some cases the other one can be slower. It all depends what you are actually doing.

There is no generic answer.

It’s just a shame you’re focusing so hard on the points that don’t actually matter. Don’t worry about optimizing your code before you’ve even written any. Go build your game and then go back and determine what you need to improve. Chances are it won’t be the portions you actually think are slow.

2 Likes

If that so then I will continue doing thing my own way.

How do you know that the thing you’re doing is right or wrong? What is you trying to experiment thing and you don’t know what you doing it right or wrong?

If the question is if is a performance issue or problem if break things up into steps or combine them, then no, it isn’t a significant issue. You are fine breaking them into separate lines if you prefer and it is easier to read for you.

1 Like

Sometime it just piss me off that I always do thing differently from other people. I remember quiting learning guitar for 2 week because I can’t do the barre chord. I just try and try to get pass that and thing become easier.

Yeah, It’s easier to read and understand. I sometime get confuse with other people’s code that why I always do thing my own way.

Experience and a profiler.

https://unity3d.com/learn/tutorials/modules/intermediate/editor/intro-to-profiler

1 Like