Game 1: Pong
This was my first game I made. I fallowed two tutorials. Started with Game Makers Toolkit unity tutorial for complete beginners and then needing some help on some functionality I used Zigurous pong walk through. I learned a lot more from GMTKs, I was hesitant on just copying a game tutorial, I don’t tend to learn anything from just copying, but I am such a beginner I started by programming the balls physics manually instead of using the Unity physics engine. I wanted to go over some thing I learned..
Learned:
GameObject
Things seems to focus around game objects in unity.
- Logic managers are basically scripts. You can get a tagged game object with
gameManager = GameObject.FindGameObjectWithTag("Manager").GetComponent<GameManagerScript>();
- You can make prefabs by dragging a component into you asset folder
- Instantiate objects, in this code ballPrefab is a
public
variable passed inball = Instantiate(ballPrefab, transform.position, transform.rotation);
- Get other components from a game object
ballscript = currentBall.GetComponent<ballscript>();
Script lifecycle physics and time
Awake
VSStart
: Use Awake to set up references between scripts, and use Start to pass any information back and forth. Awake is always called before any Start functions.Update
vsFixedUpdate
: Update runs once per frame. FixedUpdate can run once, zero, or several times per frame, depending on how many physics frames per second are set in the time settings, and how fast/slow the framerate is. It’s for this reason that FixedUpdate should be used when applying forces, torques, or other physics-related functions. Because you know it will be executed exactly in sync with the physics engine itself.- The ball was going though the walls when moving really fast, this video helped me fix it by changing the
RigidBody
collision detection to beContinuous
. - A timer can be made with is piece of code:
float timer = 0f;
// ...
void Update()
{
timer += Time.deltaTime;
if(timer > 1){
// do stuff
}
}
Mouse and keyboard controlls only
Demo available on screens larger then 960px.