This commit is contained in:
Gerard Gascón 2025-04-24 14:23:29 +02:00
commit bd5b1556ff
269 changed files with 6249829 additions and 0 deletions

View file

@ -0,0 +1,52 @@
using UnityEngine.Audio;
using System;
using UnityEngine;
public class AudioManager : MonoBehaviour{
public AudioMixerGroup mixerGroup;
public Sound[] sounds;
public static AudioManager instance;
// Start is called before the first frame update
void Awake(){
if (instance == null)
instance = this;
else{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(gameObject);
foreach (Sound s in sounds){
s.source = gameObject.AddComponent<AudioSource>();
s.source.clip = s.clip;
s.source.volume = s.volume;
s.source.pitch = s.pitch;
s.source.loop = s.loop;
s.source.outputAudioMixerGroup = mixerGroup;
}
}
public void Play(string name){
Sound s = Array.Find(sounds, sound => sound.name == name);
if (s == null){
Debug.LogError("Sound: " + name + " not found!");
return;
}
s.source.Play();
}
public void Stop(string name){
Sound s = Array.Find(sounds, sound => sound.name == name);
if (s == null){
Debug.LogError("Sound: " + name + " not found!");
return;
}
s.source.Stop();
}
}

View file

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

22
Assets/Scripts/Bullet.cs Normal file
View file

@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour{
public float speed;
Rigidbody2D rb2d;
void Start(){
rb2d = GetComponent<Rigidbody2D>();
rb2d.AddRelativeForce(Vector2.right * speed, ForceMode2D.Impulse);
}
void OnCollisionEnter2D(Collision2D col){
if(col.gameObject.tag == "Dragon"){
FindObjectOfType<Dragon>().TakeDamage(5);
}
Destroy(gameObject);
}
}

View file

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

View file

@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraShake : MonoBehaviour{
float shakeAmount = 0;
Vector3 startPos;
public void Shake(float amt, float length){
shakeAmount = amt;
startPos = transform.localPosition;
InvokeRepeating("DoShake", 0, 0.01f);
Invoke("StopShake", length);
}
void DoShake(){
if (shakeAmount > 0){
Vector3 camPos = transform.position;
float offsetX = Random.value * shakeAmount * 2 - shakeAmount;
float offsetY = Random.value * shakeAmount * 2 - shakeAmount;
camPos.x += offsetX;
camPos.y += offsetY;
transform.position = camPos;
}
}
void StopShake(){
CancelInvoke("DoShake");
transform.localPosition = startPos;
}
}

View file

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

View file

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CheckPoint : MonoBehaviour{
public Transform checkpointPos;
void OnTriggerEnter2D(Collider2D col){
if (col.CompareTag("Player")){
col.GetComponent<PlayerController>().lastCheckpoint = checkpointPos.position;
}
}
void OnDrawGizmos(){
Gizmos.color = Color.green;
BoxCollider2D col = GetComponent<BoxCollider2D>();
Gizmos.DrawWireCube(col.transform.position, col.size);
}
}

View file

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

View file

@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class CineCamChange : MonoBehaviour{
CinemachineVirtualCamera vcam;
// Start is called before the first frame update
void Awake(){
vcam = GetComponentInChildren<CinemachineVirtualCamera>();
vcam.gameObject.SetActive(false);
}
void OnTriggerEnter2D(Collider2D col){
if (col.CompareTag("Player")){
vcam.gameObject.SetActive(true);
}
}
void OnTriggerExit2D(Collider2D col){
if (col.CompareTag("Player")){
vcam.gameObject.SetActive(false);
}
}
}

View file

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

View file

@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DrawSceneLine : MonoBehaviour {
public Transform from;
public Transform to;
void OnDrawGizmosSelected(){
if (from != null && to != null){
Gizmos.color = Color.cyan;
Gizmos.DrawLine(from.position, to.position);
Gizmos.DrawSphere(from.position, 0.15f);
Gizmos.DrawSphere(to.position, 0.15f);
}
}
}

View file

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

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ca6dfe94bf658a440a59fe2ec2c78915
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,131 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Dragon : MonoBehaviour{
public GameObject colliderStop;
public GameObject[] diable;
public GameObject[] phase2Enable;
public GameObject[] phase3Enable;
public Vector2[] phasesPositions;
public GameObject fire;
public GameObject fireball;
public int maxHp;
public float hp;
public Transform mouth;
public CameraShake cameraShake;
Animator anim;
public int phase = 1;
bool vulnerable;
Transform player;
Transform parent;
// Start is called before the first frame update
void Start(){
parent = GetComponentInParent<Transform>();
anim = GetComponent<Animator>();
hp = maxHp;
vulnerable = false;
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
foreach(GameObject g in diable){
g.SetActive(false);
}
if(phase == 2){
anim.SetBool("Phase2", true);
}else if(phase == 3){
anim.SetBool("Phase2", true);
anim.SetBool("Phase3", true);
}
Invoke("DisableColliderStop", 2f);
}
void DisableColliderStop(){
colliderStop.SetActive(false);
}
float speed;
// Update is called once per frame
void Update(){
if(phase == 1){
if(hp <= 60){
phase = 2;
anim.SetBool("Die", true);
foreach (GameObject g in diable){
g.SetActive(false);
}
foreach (GameObject g in phase2Enable){
g.SetActive(true);
}
}
}else if(phase == 2){
if (hp <= 30){
phase = 3;
anim.SetBool("Die", true);
foreach (GameObject g in diable){
g.SetActive(false);
}
foreach (GameObject g in phase3Enable){
g.SetActive(true);
}
}
}else if(phase == 3){
if(hp <= 0){
Die();
}
}
}
void Die(){
anim.SetBool("Die", true);
}
public void TakeDamage(float amt){
if (vulnerable){
hp = Mathf.Clamp(hp - amt, 0f, maxHp);
}
}
public void IsIdle(){
vulnerable = true;
}
public void Shake(){
cameraShake.Shake(.1f, 1.5f);
AudioManager.instance.Play("DragonShout");
}
public void FireSound(){
AudioManager.instance.Play("DragonFire");
}
public void FireAttack(){
vulnerable = false;
Instantiate(fire, mouth.position, Quaternion.identity, mouth);
}
public void EndFireAttack(){
vulnerable = true;
}
public void FireBallAtack(){
AudioManager.instance.Play("DragonFireBall");
vulnerable = false;
Instantiate(fireball, mouth.position, Quaternion.Euler(0, 0, 90f));
}
public void EndFireBallAttack(){
vulnerable = true;
}
public void Win(){
StartCoroutine(WinScreen());
}
IEnumerator WinScreen(){
yield return new WaitForSeconds(2f);
SceneManager.LoadScene(0);
}
}

View file

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

View file

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Goomba : MonoBehaviour{
public float speed;
public float maxSpeed;
Rigidbody2D rb2d;
bool canMove;
// Start is called before the first frame update
void Start(){
rb2d = GetComponent<Rigidbody2D>();
}
void OnBecameVisible(){
canMove = true;
}
// Update is called once per frame
void Update(){
rb2d.AddForce(Vector2.left * speed);
float limitedSpeed = Mathf.Clamp(rb2d.velocity.x, -maxSpeed, maxSpeed);
rb2d.velocity = new Vector2(limitedSpeed, rb2d.velocity.y);
}
}

View file

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

View file

@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Fireball : MonoBehaviour{
public float speed;
public float attackSpeed;
public GameObject explosion;
// Start is called before the first frame update
void Start(){
StartCoroutine(Attack());
}
// Update is called once per frame
void Update(){
transform.Translate(Vector3.right * speed * Time.deltaTime);
}
IEnumerator Attack(){
yield return new WaitForSeconds(2f);
transform.position = new Vector2(GameObject.FindGameObjectWithTag("Player").transform.position.x, transform.position.y);
speed = -attackSpeed;
}
void OnCollisionEnter2D(Collision2D col){
Instantiate(explosion, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}

View file

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

69
Assets/Scripts/Grapple.cs Normal file
View file

@ -0,0 +1,69 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Grapple : MonoBehaviour{
public GameObject selector;
public float rotationSpeed;
Rigidbody2D rb2d;
GameObject player;
void Start(){
rb2d = GetComponent<Rigidbody2D>();
player = GameObject.FindGameObjectWithTag("Player");
selector.SetActive(false);
}
void Update(){
selector.transform.Rotate(0, 0, rotationSpeed);
}
void OnMouseOver(){
if (Vector2.Distance(player.transform.position, transform.position) <= 10){
selector.SetActive(true);
player.GetComponent<PlayerController>().ableToGrapple = true;
}else{
selector.SetActive(false);
}
}
bool grappled;
void OnMouseExit(){
if (!grappled){
selector.SetActive(false);
if (!player.GetComponent<PlayerController>().grappled){
player.GetComponent<PlayerController>().ableToGrapple = false;
}
}
}
void OnMouseDown(){
if(Vector2.Distance(player.transform.position, transform.position) <= 10){
grappled = true;
SpringJoint2D grapple = player.GetComponent<SpringJoint2D>();
player.GetComponent<PlayerController>().grappled = true;
player.GetComponent<CapsuleCollider2D>().isTrigger = true;
LineRenderer line = player.GetComponent<LineRenderer>();
line.SetPosition(1, transform.position);
line.enabled = true;
grapple.connectedBody = rb2d;
grapple.distance = Vector2.Distance(player.transform.position, transform.position) - 1f;
grapple.enabled = true;
}
}
void OnMouseUp(){
grappled = false;
SpringJoint2D grapple = player.GetComponent<SpringJoint2D>();
LineRenderer line = player.GetComponent<LineRenderer>();
player.GetComponent<PlayerController>().grappled = false;
player.GetComponent<CapsuleCollider2D>().isTrigger = false;
line.enabled = false;
grapple.enabled = false;
selector.SetActive(false);
player.GetComponent<PlayerController>().ableToGrapple = false;
}
}

View file

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

35
Assets/Scripts/Menu.cs Normal file
View file

@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class Menu : MonoBehaviour{
public CinemachineVirtualCamera cam;
public GameObject canvas;
// Start is called before the first frame update
void Awake(){
Time.timeScale = 0;
}
// Update is called once per frame
void Update(){
}
public void Play(){
Time.timeScale = 1;
cam.gameObject.SetActive(false);
StartCoroutine(DisableCanvas());
}
public void Quit(){
Application.Quit();
}
IEnumerator DisableCanvas(){
yield return new WaitForSeconds(1f);
canvas.SetActive(false);
}
}

View file

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

View file

@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectSpawner : MonoBehaviour{
public GameObject objectToSpawn;
public Vector2 whereToSpawn;
public float nextSpawn;
public float spawnRate = 2f;
// Start is called before the first frame update
void Start(){
}
// Update is called once per frame
void Update(){
if (Time.time > nextSpawn){
nextSpawn = Time.time + spawnRate;
Instantiate(objectToSpawn, whereToSpawn, Quaternion.identity);
}
}
}

View file

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

View file

@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlataformaFalling : MonoBehaviour {
public float fallDelay = 1f;
public float respawnDelay = 5f;
private Rigidbody2D rb2d;
private PolygonCollider2D pc2d;
private Vector3 start;
// Use this for initialization
void Start () {
rb2d = GetComponent<Rigidbody2D>();
pc2d = GetComponent<PolygonCollider2D>();
start = transform.position;
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter2D(Collision2D col){
if (col.gameObject.CompareTag("Player")){
Invoke("Fall", fallDelay);
Invoke("Respawn", fallDelay + respawnDelay);
}
}
void Fall(){
rb2d.isKinematic = false;
pc2d.isTrigger = true;
}
void Respawn(){
transform.position = start;
rb2d.isKinematic = true;
rb2d.velocity = Vector3.zero;
pc2d.isTrigger = false;
}
}

View file

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

View file

@ -0,0 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlataformaMovil : MonoBehaviour {
public Transform target;
public float speed;
public bool enableOnCollision;
bool working;
private Vector3 start, end;
// Use this for initialization
void Start () {
if (!enableOnCollision){
working = true;
}
if(target != null) {
target.parent = null;
start = transform.position;
end = target.position;
}
}
// Update is called once per frame
void Update () {
}
void FixedUpdate(){
if (target != null && working) {
float fixedSpeed = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, fixedSpeed);
}
if (transform.position == target.position){
target.position = (target.position == start) ? end : start;
}
}
void OnCollisionEnter2D(Collision2D col){
if(col.gameObject.tag == "Player"){
if (enableOnCollision){
working = true;
}
}
}
}

View file

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

View file

@ -0,0 +1,135 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour{
[HideInInspector]
public Vector2 lastCheckpoint;
public SpriteRenderer[] deathDisable;
public float speed;
public float airSpeed;
[HideInInspector]
public bool grappled;
[HideInInspector]
public bool ableToGrapple;
[Header("Jump")]
public float jumpForce;
public float groundDetectionRadius;
public LayerMask whatIsGround;
[Space(10)]
public GameObject death;
public Transform gun;
public Transform firePos;
LineRenderer line;
bool dead;
bool moving;
bool jump;
bool isGrounded;
Rigidbody2D rb2d;
Shoot shoot;
// Start is called before the first frame update
void Start(){
AudioManager.instance.Play("Theme");
shoot = GetComponent<Shoot>();
rb2d = GetComponent<Rigidbody2D>();
line = GetComponent<LineRenderer>();
lastCheckpoint = transform.position;
}
// Update is called once per frame
void Update(){
if (!dead){
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float rotZ = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
gun.transform.rotation = Quaternion.Euler(0f, 0f, rotZ);
isGrounded = Physics2D.OverlapCircle(transform.position, groundDetectionRadius, whatIsGround);
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
jump = true;
}
}
void LateUpdate(){
line.SetPosition(0, firePos.position);
}
private void OnDrawGizmosSelected(){
Gizmos.DrawWireSphere(transform.position, groundDetectionRadius);
}
void FixedUpdate(){
if (!dead){
if (!moving && isGrounded){
float fixedVelocity = rb2d.angularVelocity;
fixedVelocity *= .98f;
rb2d.angularVelocity = fixedVelocity;
}
float h = Input.GetAxisRaw("Horizontal");
if (h != 0){
moving = true;
}else{
moving = false;
}
if (isGrounded && !grappled){
rb2d.AddForce(Vector2.right * speed * h);
float limitedSpeed = Mathf.Clamp(rb2d.velocity.x, -speed, speed);
rb2d.velocity = new Vector2(limitedSpeed, rb2d.velocity.y);
}else if (!grappled){
rb2d.AddForce(Vector2.right * airSpeed * h);
float limitedSpeed = Mathf.Clamp(rb2d.velocity.x, -airSpeed, airSpeed);
rb2d.velocity = new Vector2(limitedSpeed, rb2d.velocity.y);
}
if (Input.GetMouseButton(0) && !ableToGrapple){
shoot.Fire();
}
if (jump){
rb2d.velocity = new Vector2(rb2d.velocity.x, 0);
rb2d.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
jump = false;
}
}
}
void OnParticleCollision(GameObject col){
Instantiate(death, transform.position, Quaternion.identity);
Die();
}
void OnCollisionEnter2D(Collision2D col){
if(col.gameObject.tag == "Death"){
Instantiate(death, transform.position, Quaternion.identity);
Die();
}
}
void Die(){
foreach(SpriteRenderer s in deathDisable){
s.enabled = false;
}
GetComponent<CapsuleCollider2D>().isTrigger = true;
Invoke("Respawn", 2f);
dead = true;
rb2d.bodyType = RigidbodyType2D.Static;
}
void Respawn(){
transform.position = lastCheckpoint;
foreach (SpriteRenderer s in deathDisable){
s.enabled = true;
}
GetComponent<CapsuleCollider2D>().isTrigger = false;
rb2d.bodyType = RigidbodyType2D.Dynamic;
rb2d.velocity = Vector2.zero;
dead = false;
}
}

View file

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

26
Assets/Scripts/Shoot.cs Normal file
View file

@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shoot : MonoBehaviour{
public float timeBetweenShots;
public Transform firePoint;
public GameObject bullet;
float lastTimeShot;
float shotCounter;
public void Fire(){
if (Time.time > lastTimeShot + timeBetweenShots){
shotCounter -= Time.deltaTime;
if (shotCounter <= 0){
lastTimeShot = Time.time;
shotCounter = timeBetweenShots;
Instantiate(bullet, firePoint.position, firePoint.rotation);
}
}else{
shotCounter = 0;
}
}
}

View file

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

22
Assets/Scripts/Sound.cs Normal file
View file

@ -0,0 +1,22 @@
using UnityEngine.Audio;
using UnityEngine;
[System.Serializable]
public class Sound{
public string name;
public AudioClip clip;
[Range(0f, 1f)]
public float volume = 1f;
[Range(0.1f, 3f)]
public float pitch = 1f;
public bool loop;
public AudioMixerGroup mixerGroup;
[HideInInspector]
public AudioSource source;
}

View file

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

View file

@ -0,0 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpikyBall : MonoBehaviour{
void OnTriggerEnter2D(Collider2D col){
if(col.gameObject.tag == "BallDestroyer"){
Destroy(gameObject);
}
}
}

View file

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

View file

@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TriggerEnableAndDisable : MonoBehaviour{
public GameObject enable;
public GameObject disable;
public float delay;
void OnTriggerEnter2D(Collider2D col){
if(col.gameObject.tag == "Player"){
if(delay == 0){
if (enable != null){
enable.SetActive(true);
}
if (disable != null){
disable.SetActive(false);
}
gameObject.SetActive(false);
}else{
StartCoroutine(Delay());
}
}
}
IEnumerator Delay(){
yield return new WaitForSeconds(delay);
if (enable != null){
enable.SetActive(true);
}
if (disable != null){
disable.SetActive(false);
}
gameObject.SetActive(false);
}
}

View file

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