init
This commit is contained in:
commit
9afd57306d
323 changed files with 204673 additions and 0 deletions
54
Assets/Scripts/Game07/PlayerController07.cs
Normal file
54
Assets/Scripts/Game07/PlayerController07.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class PlayerController07 : MonoBehaviour{
|
||||
|
||||
public GameObject death;
|
||||
public string menuScene;
|
||||
public string[] scenes;
|
||||
public Image timeBar;
|
||||
public float maxTime = 5;
|
||||
float currentTime;
|
||||
Rigidbody2D rb2d;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
currentTime = maxTime;
|
||||
rb2d = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
currentTime -= 1 * Time.deltaTime;
|
||||
timeBar.transform.localScale = new Vector2(currentTime / maxTime, timeBar.transform.localScale.y);
|
||||
if (currentTime <= 0){
|
||||
StartCoroutine(Death());
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerStay2D(Collider2D col){
|
||||
if (rb2d.velocity.y < 0){
|
||||
CompleteLevel();
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Death(){
|
||||
Time.timeScale = 0;
|
||||
death.SetActive(true);
|
||||
yield return new WaitForSecondsRealtime(4f);
|
||||
LoseGame();
|
||||
}
|
||||
|
||||
public void CompleteLevel(){
|
||||
string scene = scenes[Random.Range(0, scenes.Length - 1)];
|
||||
LevelLoader.Instance.LoadLevel(scene);
|
||||
}
|
||||
|
||||
public void LoseGame(){
|
||||
Debug.LogError(SceneManager.GetActiveScene().name);
|
||||
LevelLoader.Instance.LoadLevel(menuScene);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue