Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Player: MonoBehaviour {
- public Rigidbody2D myRigidbody { get; set; }
- public float jumpForce = 2.0f;
- [SerializeField]
- public Animator animator;
- public bool isDead = true;
- public GameManager gameManager;
- public bool IsDead
- {
- get
- {
- return isDead;
- }
- }
- void Start () {
- myRigidbody = GetComponent<Rigidbody2D>();
- }
- void Update () {
- if (Input.GetMouseButtonDown(0) && !IsDead)
- {
- jump = true;
- animator.SetBool("jump", true);
- }else
- {
- animator.SetBool("jump", false);
- }
- }
- public void OnTriggerEnter2D(Collider2D collision)
- {
- if (!isDead && collision.tag == "Obstacle")
- {
- StartCoroutine(Die());
- }
- }
- public IEnumerator Die()
- {
- isDead = true;
- animator.SetBool("Die", true);
- yield return new WaitForSeconds(2);
- gameManager.GameOver();
- }
- public void Jump()
- {
- myRigidbody.AddForce(jumpForce* Vector2.up, ForceMode2D.Impulse);
- }
- public enum GameStates { Start, InGame, GameOver};
- [SerializeField]
- private Player player;
- [SerializeField]
- private Player player1;
- public GameObject startPanel, ingamePanel, gameoverPanel;
- void Update () {
- if(player.IsDead )
- {
- StartCoroutine(player.Die());
- GameOver();
- }
- if (player1.IsDead)
- {
- StartCoroutine(player1.Die());
- GameOver();
- }
- }
- public void GameOver()
- {
- UpdateUI(GameStates.GameOver);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement