init
This commit is contained in:
commit
9afd57306d
323 changed files with 204673 additions and 0 deletions
49
Assets/Scripts/Game12/Game12Ball.cs
Normal file
49
Assets/Scripts/Game12/Game12Ball.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Game12Ball : MonoBehaviour{
|
||||
|
||||
public GameObject particles;
|
||||
public GameObject death;
|
||||
public float speed;
|
||||
public Rigidbody2D rb2d;
|
||||
bool launched;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if(Time.timeScale > 0 && !launched){
|
||||
Launch();
|
||||
launched = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Launch(){
|
||||
float x = Random.Range(0, 2) == 0 ? -1 : 1;
|
||||
float y = Random.Range(0, 2) == 0 ? -1 : 1;
|
||||
rb2d.velocity = new Vector2(speed * x, speed * y);
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D col){
|
||||
if(col.gameObject.tag == "Finish"){
|
||||
StartCoroutine(Death());
|
||||
}else{
|
||||
AudioManager.instance.Play("Paddle");
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Death(){
|
||||
Time.timeScale = 0;
|
||||
particles.SetActive(true);
|
||||
GetComponent<SpriteRenderer>().enabled = false;
|
||||
yield return new WaitForSecondsRealtime(1f);
|
||||
death.SetActive(true);
|
||||
yield return new WaitForSecondsRealtime(5f);
|
||||
FindObjectOfType<GameController>().LoseGame();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue