Well first you have your name spaces that is imported into your script which each offers it’s own classes and constructors, built-in functionality.
// These are the NameSpaces you're importing into your project.
using System.Collections; // Deals with collections such as IEnumerators
using System.Collections.Generic; // Mostly used for List<>
using UnityEngine; // You'll use this 99% of the time
Next you have you Class and content. Everything you want to happen in your script occurs here.
// Whatever you name your script will be the Class name
// In your instance it's a poorly named "bird".
//May I encourage you to use Uppercase for classes? "Bird" instead
public class bird : MonoBehaviour {
// Here is the variables that are declared/initialized inside your script
public float jumpforce =4.1f;
// public = global and visible inside inspector
// float = a decimal based number value
// jumpForce is the name of your float variable.
// Since it's initialized upon declaration, this is known as "Hard coded"
// jumpForce = 4.1f; 4.1 is the decimal the "f" is for "float"
Rigidbody2D mybody;
// Rgidbody2D is a 2D built-in physics component.
// mybody (Would look better "myBody")
// mybody is the name of your RB variable
// Rigidbodies as most commonly used for movement
Animator myanim;
// Animator is a component attached to the GameObject
// This is like an Audio Player that stores the playlist (Basically)
// myanim (better if myAnim) is te variable name
// You will use the Animator to access animations/clips and play them
Now you’re entering a new phase zone, as I like to call it. This is after-loaded, after-starting up, now you are in the actual game and it is live and you’re playing now!
// Start is a Phase Unity goes through upon Startup
// Start phase happens after Awake()
// Unlike Awake(), the GameObjects should be loaded during this phase
void Start () {
myanim = GetComponent<Animator> ();//làm rõ
// You're initializing myanim by grabbing the component
// on the GameObject this script is attached to.
mybody = GetComponent<Rigidbody2D> ();//làm rõ
// Here you are initializing your Rigidbody2D variable
// by grabbing the Rigidbody2D component on the
// GameObject that this script is attached to
}
// [Update() is another Phase. This runs like 150 frames per second ? Maybe?]
// Update is called once per frame
// FixedUpdate() is great for calculations
// Similar to Update() only it runs 50 frames per second? Maybe? Eh, easy to look up. These are estimates lol
void FixedUpdate () {
birdjump ();
// Here you are calling a function named birdJump()
// This will run "50 frames per second" with my guestimation.
/ This will constantly be called throughout the game.
}
Finally, you’re getting past the phases of your program. Now you’re writing a mini sub-program to run at anytime you want. These are known as Methods and/or Functions. You don’t have to call these types every frame but you can, as demonstrated in your code. Which makes sense because your function is designed to listen for Left-Mouse click, which can also be translated as “Touching the screen” on a cell phone.
// This is a Function ( Also known as a Method )
// void is declaring that the Function will NOT be returning values
// Although not visible, this is a private void Function which means
// it is only accessible to this script. "private" is a protection level.
void birdjump(){
// IF statement is a Logical Evaluator. This is how you make a program think.
// Here you are "Listening" for a Keyboard INPUT from
// the mouse button.
// This particular call is for "Down" which is the moment the
//button is pressed down. This will fire once even if you hold the button down.
// GetButtonUp fires when button is released
// GetButton fires the entire time it is held down.
// This is looking for GetButtonDown(0)
// 0 is left click
// 1 is right click
// 2 is for mouse scroll-button.
if (Input.GetMouseButtonDown (0)) {
// Here you are adding a velocity physics to your Rigidbody2D component.
// You are setting it to a "new" position
// Vector2 = X-axis and Y-axis Vector3 = X,Y,Z
// This is reading your x-velocity and adding jumpforce the the Y axis.
// So looks like everytime you touch the phone screen
// your GameObject will move upwards whilst maintaining its
// X movement.
mybody.velocity = new Vector2 (mybody.velocity.x, jumpforce);
}
}
}
Hopefully you find this information useful 