Game Development Reference
In-Depth Information
void Awake() {
_animator = GetComponent<Animator>();
_boxCollider2D = GetComponent<BoxCollider2D>();
_height = _boxCollider2D.size.y;
}
void Start () {
_isFacingRight = true;
_isJump = false;
_isFall = false;
_isGrounded = false;
_gameEnd = false;
_lastY = transform.position.y;
Camera.main.transform.position = new
Vector3(transform.position.x, transform.position.y,
Camera.main.transform.position.z);
}
}
Tip
Downloading the example code
You can download the example code files for all Packt topics you have purchased
from your account at http://www.packtpub.com . If you purchased this topic else-
where, you can visit http://www.packtpub.com/support and register to have the
files e-mailed directly to you.
Note
@script RequireComponent(Component) and [RequireCompon-
ent(typeof(Component))]
We add RequireComponent to force the script to automatically add the re-
quired component as a dependency when adding this class to the game object. For
more details, visit http://docs.unity3d.com/Documentation/ScriptReference/Re-
quireComponent.html .
6. Next, we will add the Flip() function after the Start() function to make our
character sprite show the correct graphics when moving left or right. The code for
Unity JavaScript and C# users are as follows:
Search WWH ::




Custom Search