This commit is contained in:
Gerard Gascón 2025-04-24 14:20:42 +02:00
commit 9afd57306d
323 changed files with 204673 additions and 0 deletions

View file

@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Game13 : MonoBehaviour{
public GameObject enemy;
public Transform target;
public float speed;
bool canMove = true;
Vector3 start, end;
// Start is called before the first frame update
void Start(){
enemy.transform.position = new Vector2(-2, Random.Range(3.5f, -3.5f));
if (target != null){
target.parent = null;
start = transform.position;
end = target.position;
}
}
void Update(){
if (Input.GetKeyDown(KeyCode.Space)){
canMove = false;
}
}
// Update is called once per frame
void FixedUpdate(){
if (target != null){
if (canMove){
float fixedSpeed = speed * Time.fixedDeltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, fixedSpeed);
}
}
if (transform.position == target.position){
target.position = (target.position == start) ? end : start;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8a8ef7a45d4062c48a8bbe19bf41128f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,58 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Game13Bullet : MonoBehaviour{
public GameObject death;
public GameObject deathParticles;
public GameObject killParticles;
public float speed;
bool canMove;
// Start is called before the first frame update
void Start(){
}
// Update is called once per frame
void Update(){
if (canMove){
transform.Translate(Vector2.left * speed * Time.deltaTime);
}
if (Input.GetKeyDown(KeyCode.Space) && !canMove){
AudioManager.instance.Play("Shoot");
canMove = true;
}
}
void OnCollisionEnter2D(Collision2D col){
if(col.gameObject.tag == "Finish"){
GetComponent<SpriteRenderer>().enabled = false;
deathParticles.SetActive(true);
Time.timeScale = 0;
StartCoroutine(Death());
AudioManager.instance.Play("Explosion");
}else{
col.gameObject.SetActive(false);
killParticles.transform.position = col.transform.position;
killParticles.SetActive(true);
StartCoroutine(Win());
Time.timeScale = 0;
AudioManager.instance.Play("Explosion");
}
}
IEnumerator Win(){
yield return new WaitForSecondsRealtime(1f);
FindObjectOfType<GameController>().CompleteLevel();
}
IEnumerator Death(){
yield return new WaitForSecondsRealtime(1f);
death.SetActive(true);
yield return new WaitForSecondsRealtime(4f);
FindObjectOfType<GameController>().LoseGame();
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a13ca91452192ea47bee3e351bfe0928
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: