Tuesday, June 17, 2014

Simple Platformer Day 09

Static: everything used by a static function needs to also be static.
(still not super clear on what can and cannot be static, research reading later)

Crazy hackery to refer to an otherwise non-static class:

Protected static  |class| |instance name| = null;

void Awake() {
|instance name| = this;
}

Notes:
 protected = just means "members of flowerScript can see this, everyone else go away"
static = "this variable is shared by every member of this class, and you don't need to be a member to use it"
flowerScript = this is the type of our variable
m_instance = the name I picked out
"type" is like int, string, etc.
Any class you make is a type too.
null = I don't have an initial value for this, so I'm leaving it empty for now
Singleton: a clean way for static objects to be able to accept and use editor links.

  • Made a killfloor.
  • Restart function currently cannot reposition player due to  "NullReferenceException: Object reference not set to an instance of an object"

  • Need to figure out a way for restart function to wipe out all remaining flowers on screen.
  • Need to get a restart button to display on player death.

Simple Platformer Day 09

Static: everything used by a static function needs to also be static.
(still not super clear on what can and cannot be static, research reading later)

Crazy hackery to refer to an otherwise non-static class:

Protected static  |class| |instance name| = null;

void Awake() {
|instance name| = this;
}

Notes:
 protected = just means "members of flowerScript can see this, everyone else go away"
static = "this variable is shared by every member of this class, and you don't need to be a member to use it"
flowerScript = this is the type of our variable
m_instance = the name I picked out
"type" is like int, string, etc.
Any class you make is a type too.
null = I don't have an initial value for this, so I'm leaving it empty for now
Singleton: a clean way for static objects to be able to accept and use editor links.

Monday, June 16, 2014

Simple Platformer Day 08

Today: 15ish minutes to follow a tutorial, and an hour with the help of Herbie to try to unravel why I can't get the text to show up.

Lesson learned:
Do NOT attach GUI as a child or component to... everything else, because its position works differently than... everything else.

Forumer's post that helped me discover this mistake:
"Please do what I said and make the GUIText a separate object. It should not be a child of the camera, it should not be a component on the camera. It must be a totally separate independent object because it uses viewport space, not world space. It works 100% correctly: GameObject > Create Other > GUIText. Do not move it away from the 0..1 range in x/y or it won't be visible."

Solution:
Created a separate script for GUI.
 void OnGUI(){
        gameObject.guiText.text = "Score:" + GM_Cs.theScore;
    }

How position works: 0.5, 0.9 would be "upper middle of the screen".

noted for later use, changing something's position in script:

gameObject (or score.gameObject) .transform.position

Friday, June 13, 2014

Simple Platformer Day 07

Never has easy as it could be, but I learned how to define and call static functions from different scripts today.
 GM_Cs.addScore();

GetComponent only works on components that are attached to the same object.
FindObjectByName calls for object if you already know its name.

Still unsure how to use the above two to refer to non-static functions between scripts.  Need to learn eventually.

I got the score to work and to add up.  Next up: figuring out basic GUI display for the score.

Tuesday, June 10, 2014

Simple Platformer Day 06

Day 6:
With Herbie's help, figured out how to destroy flowers using both trigger and collision.

Trigger:
check "is trigger" box in unity

void OnTriggerEnter2D() { Destroy (this.gameObject);}

Collision:
uncheck the trigger box in unity

void OnCollisionEnter2D (Collsion2D col) {}
(also accidentally killed player by using Destroy (col.gameObject);  need to learn parameters correctly.)

Lunch plans:

Do the score thing, including UI.

Tomorrow+'s plan:

  • Make kill floor.
  • Make player death function that calls a reset button.
  • Spawn an enemy that walks around the right platform.
  • Make sure flowers do not collide with enemy (likely adding if tag to the collision function)
  • Allow player to kill enemy by jumping on it.
  • Trigger player death if player collides with enemy.

Monday, June 9, 2014

Simple Platformer Day 05

Got a sprite to spawn after looking up 3 different tutorials to figure out 1 phrase...

"Instantiate"!!!

Syntax: Instantiate (name, position, rotation);

Below is my cobbled-together power-up spawn script.


Next Steps:
  • Make the flowers disappear when colliding with player;
  • Create a counter that goes up by one each time a flower is walked over;
  • Display said counter in the middle of the screen.