Game Development Reference
In-Depth Information
In Unity JavaScript, we can use #pragma strict to tell Unity to disable dy-
namic typing ( var name = 5 ) and force us to use static typing ( var name :
int = 5 ). This will make it easy for us to debug. For example, if we forgot to
use static typing, you will see an error message from the Unity console window.
Using strict typing also makes the code run faster as the complier doesn't have to
go and do the type lookups.
// C# user:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
[RequireComponent(typeof(BoxCollider2D))]
[RequireComponent(typeof(Rigidbody2D))]
public class PlayerController_2D : MonoBehaviour
{
// Distance from the character position to the
ground
const float RAYCAST_DISTANCE = 0.58f;
// This number should be between 0.35 to 0.49
const float CHARACTER_EDGE_OFFSET = 0.40f;
public AudioClip doorOpenSound;
public AudioClip getKeySound;
public AudioClip jumpSound;
public float moveForce = 80f;
public float jumpForce = 350f;
public float maxSpeed = 3f;
public LayerMask layerMask;
Animator _animator;
BoxCollider2D _boxCollider2D;
bool _isFacingRight = true;
bool _isJump = false;
bool _isFall = false;
bool _isGrounded = false;
bool _gameEnd = false;
float _height;
float _lastY;
float _horizontalInput;
Search WWH ::




Custom Search