init
This commit is contained in:
commit
9afd57306d
323 changed files with 204673 additions and 0 deletions
48
Assets/Scripts/Game03/PlayerController03.cs
Normal file
48
Assets/Scripts/Game03/PlayerController03.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController03 : MonoBehaviour{
|
||||
|
||||
Rigidbody2D rb2d;
|
||||
public float flapForce;
|
||||
public GameObject explosion;
|
||||
public GameObject death;
|
||||
|
||||
bool jump;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
rb2d = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (Input.GetKeyDown(KeyCode.Space)){
|
||||
jump = true;
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
if (jump){
|
||||
rb2d.velocity = Vector2.zero;
|
||||
rb2d.AddForce(Vector2.up * flapForce, ForceMode2D.Impulse);
|
||||
jump = false;
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D col){
|
||||
AudioManager.instance.Play("Hit");
|
||||
Time.timeScale = 0f;
|
||||
GetComponent<SpriteRenderer>().enabled = false;
|
||||
explosion.SetActive(true);
|
||||
StartCoroutine(Death());
|
||||
}
|
||||
|
||||
IEnumerator Death(){
|
||||
yield return new WaitForSecondsRealtime(1f);
|
||||
death.SetActive(true);
|
||||
yield return new WaitForSecondsRealtime(4.5f);
|
||||
FindObjectOfType<GameController>().LoseGame();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue