consolidate all repos to one for archive
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22588ff2cd583d345a7c8ed25dbe63b4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,166 @@
|
||||
using Pathfinding;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
//using static Pathfinding.Util.GridLookup<T>;
|
||||
using Quaternion = UnityEngine.Quaternion;
|
||||
using Vector2 = UnityEngine.Vector2;
|
||||
|
||||
public class Enemy : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] GameObject bulletPrefab;
|
||||
[SerializeField] GameObject bombPrefab;
|
||||
[SerializeField] GameObject splitStarPrefab;
|
||||
[SerializeField] GameObject splitThreePrefab;
|
||||
|
||||
|
||||
public int shootingType = 0;
|
||||
public int bulletType = 0;
|
||||
public int framesBetwenShoot = 60;
|
||||
public int booletSpeet = 5;
|
||||
GameObject _player;
|
||||
int _frameCounter = 0;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
var gameObjectP = GameObject.Find("Player");
|
||||
if (gameObjectP == null) return;
|
||||
_player = gameObjectP;
|
||||
|
||||
|
||||
|
||||
GetComponent<Helth>().livePoints = Random.Range(1, 3);
|
||||
booletSpeet = Random.Range(9, 10);
|
||||
|
||||
var BombSettings = bombPrefab.GetComponent<PBomb>();
|
||||
BombSettings.Player = _player;
|
||||
|
||||
if (bulletType > 3) bulletType = Random.Range(0, 4);
|
||||
if (shootingType > 2) shootingType = Random.Range(0, 3);
|
||||
|
||||
var aiDest = GetComponent<AIDestinationSetter>();
|
||||
if (aiDest == null) return;
|
||||
aiDest.target = _player.transform;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
if(_player == null) return;
|
||||
|
||||
//get distance to player
|
||||
if(_frameCounter == framesBetwenShoot)
|
||||
{
|
||||
var distance = Vector2.Distance(transform.position, _player.transform.position);
|
||||
if (distance > 10) return;
|
||||
switch (shootingType)
|
||||
{
|
||||
case 0:
|
||||
ShootOne();
|
||||
break;
|
||||
case 1:
|
||||
ShootAll();
|
||||
break;
|
||||
case 2:
|
||||
ShootTree();
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
_frameCounter = 0;
|
||||
}
|
||||
_frameCounter++;
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D other)
|
||||
{
|
||||
// If a bullet hits an enemy, destroy the enemy object and the bullet itself.
|
||||
if (other.gameObject.CompareTag("Player"))
|
||||
{
|
||||
|
||||
other.gameObject.GetComponent<Helth>().TakeDamage(1);
|
||||
}
|
||||
}
|
||||
|
||||
void ShootOne()
|
||||
{
|
||||
Vector2 vector2 = transform.position;
|
||||
GameObject bullet = bulletType switch
|
||||
{
|
||||
1 => (GameObject)Instantiate(bombPrefab, vector2, Quaternion.identity),
|
||||
2 => (GameObject)Instantiate(splitStarPrefab, vector2, Quaternion.identity),
|
||||
3 => (GameObject)Instantiate(splitThreePrefab, vector2, Quaternion.identity),
|
||||
_ => (GameObject)Instantiate(bulletPrefab, vector2, Quaternion.identity),
|
||||
};
|
||||
|
||||
// Add velocity to the bullet
|
||||
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
|
||||
|
||||
//vector from enemy to player
|
||||
Vector2 direction = _player.transform.position - transform.position;
|
||||
direction.Normalize();
|
||||
rb.AddForce(direction * booletSpeet, ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
static Vector2[] directions = new Vector2[8]
|
||||
{
|
||||
new Vector2(1, 0),
|
||||
new Vector2(0.7f, 0.7f),
|
||||
new Vector2(0, 1),
|
||||
new Vector2(-0.7f, 0.7f),
|
||||
new Vector2(-1, 0),
|
||||
new Vector2(-0.7f, -0.7f),
|
||||
new Vector2(0, -1),
|
||||
new Vector2(0.7f, -0.7f)
|
||||
};
|
||||
|
||||
void ShootAll()
|
||||
{
|
||||
foreach (Vector2 direction in directions)
|
||||
{
|
||||
GameObject bullet = bulletType switch
|
||||
{
|
||||
1 => (GameObject)Instantiate(bombPrefab, transform.position, Quaternion.identity),
|
||||
2 => (GameObject)Instantiate(splitStarPrefab, transform.position, Quaternion.identity),
|
||||
3 => (GameObject)Instantiate(splitThreePrefab, transform.position, Quaternion.identity),
|
||||
_ => (GameObject)Instantiate(bulletPrefab, transform.position, Quaternion.identity),
|
||||
};
|
||||
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
|
||||
rb.AddForce(direction * booletSpeet, ForceMode2D.Impulse);
|
||||
}
|
||||
}
|
||||
|
||||
static float[] angles = new float[3] { 10, 0, -10 };
|
||||
void ShootTree()
|
||||
{
|
||||
Vector2 vector2 = transform.position;
|
||||
Vector2 playerDirection = _player.transform.position - transform.position;
|
||||
playerDirection.Normalize();
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
GameObject bullet = bulletType switch
|
||||
{
|
||||
1 => (GameObject)Instantiate(bombPrefab, vector2, Quaternion.identity),
|
||||
2 => (GameObject)Instantiate(splitStarPrefab, vector2, Quaternion.identity),
|
||||
3 => (GameObject)Instantiate(splitThreePrefab, vector2, Quaternion.identity),
|
||||
_ => (GameObject)Instantiate(bulletPrefab, vector2, Quaternion.identity),
|
||||
};
|
||||
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
|
||||
|
||||
// Create a quaternion representing the rotation
|
||||
Quaternion rotation = Quaternion.Euler(0f, 0f, angles[i]);
|
||||
|
||||
// Rotate the vector using the quaternion
|
||||
Vector2 direction = rotation * playerDirection;
|
||||
|
||||
rb.AddForce(direction * booletSpeet, ForceMode2D.Impulse);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7be6279cfd5a0c648acce27a2e3e78ae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class NextSceen : MonoBehaviour
|
||||
{
|
||||
public GameObject boss;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if(boss == null)
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 645d48dd25af7174f8607ae9a6594e6b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PBomb : MonoBehaviour
|
||||
{
|
||||
public GameObject Player;
|
||||
public int damage = 5;
|
||||
public float distacneToDealDamage = 1f;
|
||||
public int timeToExplode = 60;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Destroy(gameObject, 2f);
|
||||
}
|
||||
|
||||
int _frameCounter = 0;
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (Player == null) return;
|
||||
|
||||
if (_frameCounter == timeToExplode)
|
||||
{
|
||||
Explode();
|
||||
}
|
||||
_frameCounter++;
|
||||
}
|
||||
|
||||
void Explode()
|
||||
{
|
||||
if(Player == null) return;
|
||||
float distance = Vector2.Distance(transform.position, Player.transform.position);
|
||||
|
||||
//if distance is less than 0.5f, destroy the bullet
|
||||
if (distance < distacneToDealDamage)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
Player.GetComponent<Helth>().TakeDamage(damage);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.gameObject.CompareTag("Player"))
|
||||
{
|
||||
Explode();
|
||||
}
|
||||
// If a bullet hits an obstacle (walls..), just destroy the bullet.
|
||||
else if (other.gameObject.CompareTag("Obstacle"))
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43947ddcec7e3ae4481b0f93ea2f9add
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PBullet : MonoBehaviour
|
||||
{
|
||||
public int damage = 1;
|
||||
private void Start()
|
||||
{
|
||||
//Destroy after 2s if we don't hit anything.
|
||||
Destroy(gameObject, 2f);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
|
||||
if (other.gameObject.CompareTag("Player"))
|
||||
{
|
||||
Destroy(gameObject);
|
||||
other.gameObject.GetComponent<Helth>().TakeDamage(damage);
|
||||
}
|
||||
// If a bullet hits an obstacle (walls..), just destroy the bullet.
|
||||
else if (other.gameObject.CompareTag("Obstacle"))
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef6cd0a526aa5a242b80e0bc27788fa0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,113 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PSplit : MonoBehaviour
|
||||
{
|
||||
[SerializeField] GameObject bulletPrefab;
|
||||
[SerializeField] GameObject bombPrefab;
|
||||
public int timeToSplit = 60;
|
||||
public int booletSpeet = 5;
|
||||
public int shootingType = 0;
|
||||
|
||||
GameObject bulletToShoot;
|
||||
void Start()
|
||||
{
|
||||
Destroy(gameObject, 2f);
|
||||
if (Random.value > 0.5)
|
||||
{
|
||||
bulletToShoot = bulletPrefab;
|
||||
}
|
||||
else
|
||||
{
|
||||
bulletToShoot = bombPrefab;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int _frameCounter = 0;
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (_frameCounter == timeToSplit)
|
||||
{
|
||||
Split();
|
||||
}
|
||||
_frameCounter++;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
|
||||
if (other.gameObject.CompareTag("Player"))
|
||||
{
|
||||
other.gameObject.GetComponent<Helth>().TakeDamage(1);
|
||||
Split();
|
||||
}
|
||||
// If a bullet hits an obstacle (walls..), just destroy the bullet.
|
||||
else if (other.gameObject.CompareTag("Obstacle"))
|
||||
{
|
||||
Split();
|
||||
}
|
||||
}
|
||||
|
||||
void Split()
|
||||
{
|
||||
switch (shootingType)
|
||||
{
|
||||
case 0:
|
||||
ShootAll();
|
||||
break;
|
||||
case 1:
|
||||
ShootTree();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
static Vector2[] directions = new Vector2[8]
|
||||
{
|
||||
new Vector2(1, 0),
|
||||
new Vector2(0.7f, 0.7f),
|
||||
new Vector2(0, 1),
|
||||
new Vector2(-0.7f, 0.7f),
|
||||
new Vector2(-1, 0),
|
||||
new Vector2(-0.7f, -0.7f),
|
||||
new Vector2(0, -1),
|
||||
new Vector2(0.7f, -0.7f)
|
||||
};
|
||||
|
||||
void ShootAll()
|
||||
{
|
||||
foreach (Vector2 direction in directions)
|
||||
{
|
||||
GameObject bullet = Instantiate(bulletToShoot, transform.position, Quaternion.identity);
|
||||
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
|
||||
rb.AddForce(direction * booletSpeet, ForceMode2D.Impulse);
|
||||
}
|
||||
}
|
||||
|
||||
static float[] angles = new float[3] { 10, 0, -10 };
|
||||
void ShootTree()
|
||||
{
|
||||
Vector2 vector2 = transform.position;
|
||||
Vector2 playerDirection = GetComponent<Rigidbody2D>().velocity;
|
||||
playerDirection.Normalize();
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
GameObject bullet = Instantiate(bulletToShoot, vector2, Quaternion.identity);
|
||||
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
|
||||
|
||||
// Create a quaternion representing the rotation
|
||||
Quaternion rotation = Quaternion.Euler(0f, 0f, angles[i]);
|
||||
|
||||
// Rotate the vector using the quaternion
|
||||
Vector2 direction = rotation * playerDirection;
|
||||
|
||||
rb.AddForce(direction * booletSpeet, ForceMode2D.Impulse);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5c4bcba1f929e043b5dad054917c351
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Pathfinding;
|
||||
|
||||
public class SpawnerScript : MonoBehaviour
|
||||
{
|
||||
public GameObject enemy;
|
||||
float summonTime = 5;
|
||||
public float minSummonTime = 1;
|
||||
public float maxSummonTime = 5;
|
||||
public float summonRadius = 5;
|
||||
public int minSummonAmount = 5;
|
||||
public int maxSummonAmount = 10;
|
||||
int summonAmount = 1;
|
||||
float summon = 0;
|
||||
|
||||
GameObject _player;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
var gameObjectP = GameObject.Find("Player");
|
||||
if (gameObjectP == null) return;
|
||||
_player = gameObjectP;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
if( Time.fixedTime - summon > summonTime){
|
||||
|
||||
if(_player == null) return;
|
||||
var distance = Vector2.Distance(transform.position, _player.transform.position);
|
||||
if (distance > 25) return;
|
||||
|
||||
for (int i = 0; i < summonAmount; i++)
|
||||
{
|
||||
Vector2 pos = Random.insideUnitCircle * summonRadius;
|
||||
pos += new Vector2(transform.position.x, transform.position.y);
|
||||
Instantiate(enemy, pos, Quaternion.identity);
|
||||
}
|
||||
summonAmount = Mathf.RoundToInt(Random.Range(minSummonAmount, maxSummonAmount));
|
||||
summonTime = Random.Range(summonTime, summonAmount);
|
||||
|
||||
summon = Time.fixedTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f518c39f91294254c8986b7e870ad14f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class Helth : MonoBehaviour
|
||||
{
|
||||
private GameObject player;
|
||||
public int livePoints = 1;
|
||||
public int maxHealth = 8;
|
||||
public Healthbar healthbar;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (healthbar == null) return;
|
||||
healthbar.SetMaxHealth(maxHealth);
|
||||
|
||||
}
|
||||
|
||||
public void TakeDamage(int damage)
|
||||
{
|
||||
livePoints -= damage;
|
||||
if (livePoints <= 0)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
if(healthbar != null)
|
||||
{
|
||||
healthbar.setHealth(livePoints);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9eefcd1d14468de4181a4b0a7bd87483
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8044500d54572322a2ce7f1dda67feb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 048a53d220c12d143872563e2455666b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Bomb : MonoBehaviour
|
||||
{
|
||||
public float bombRadius = 5f;
|
||||
public float bombForce = 10f;
|
||||
public int bombDamage = 1;
|
||||
|
||||
public void Explode()
|
||||
{
|
||||
Debug.Log("Explode");
|
||||
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, bombRadius); // Find all colliders in the bomb radius.
|
||||
|
||||
foreach (Collider2D collider in colliders)
|
||||
{
|
||||
if (!collider.gameObject.CompareTag("Player"))
|
||||
{
|
||||
Rigidbody2D rb = collider.GetComponent<Rigidbody2D>(); // Get the rigidbody of each collider.
|
||||
if (rb != null)
|
||||
{
|
||||
Vector2 explosionDirection = (rb.transform.position - transform.position).normalized; // Get the direction of rigidbody from the bomb, normalize to disregard distance and focus on direction.
|
||||
float distance = Vector2.Distance(transform.position, rb.transform.position); // Calculate the distance between the bomb and the collider.
|
||||
float explosionPower = 1 - distance / bombRadius; // 1 -> max damage, so we subtract how far the object is from the bomb explosion radius.
|
||||
explosionPower = Mathf.Clamp(explosionPower, 0f, 1f); // Adjust damage according to distance from explosion but not less than 0 and not more than 1.
|
||||
rb.AddForce(explosionDirection * bombForce * explosionPower, ForceMode2D.Impulse); // Add the force to the rigidbody.
|
||||
}
|
||||
|
||||
if (collider.gameObject.CompareTag("Enemy"))
|
||||
{
|
||||
collider.gameObject.GetComponent<Helth>().TakeDamage(bombDamage);
|
||||
Debug.Log("Damage dealt to enemy: " + collider.gameObject.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public IEnumerator ExplodeWithDelay(float delay)
|
||||
{
|
||||
Debug.Log("ExplodeWithDelay");
|
||||
yield return new WaitForSeconds(delay);
|
||||
Explode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49b510a4c4691aa5aa0ad5836011b72e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- bombPrefab: {fileID: 9030852861077885179, guid: 29024e0d8a29bd622863d821f3432598, type: 3}
|
||||
executionOrder: -29000
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class HitBomb : MonoBehaviour
|
||||
{
|
||||
private Bomb bomb;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
bomb = GetComponent<Bomb>();
|
||||
}
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D other)
|
||||
{
|
||||
if (other.gameObject.CompareTag("Enemy") || other.gameObject.CompareTag("Obstacle"))
|
||||
{
|
||||
Debug.Log("Bomb triggered by: " + other.gameObject.name);
|
||||
if (bomb != null)
|
||||
{
|
||||
StartCoroutine(bomb.ExplodeWithDelay(0.2f));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71e68eca6d28aeab994716755ab4e854
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Teleport : MonoBehaviour
|
||||
{
|
||||
public PlayerController playerController;
|
||||
public float teleportDistance;
|
||||
public bool onCooldown;
|
||||
public int cooldownDuration = 5;
|
||||
void Start()
|
||||
{
|
||||
playerController = GetComponent<PlayerController>();
|
||||
teleportDistance = 0.5f;
|
||||
onCooldown = false;
|
||||
}
|
||||
|
||||
public void TeleportPlayer(){
|
||||
StartCoroutine(TeleportCoroutine());
|
||||
}
|
||||
|
||||
IEnumerator TeleportCoroutine(){
|
||||
|
||||
var player = playerController.transform;
|
||||
Vector3 forward = player.up;
|
||||
Vector3 newPosition = player.position + forward * teleportDistance;
|
||||
var spriteRenderer = player.GetComponent<SpriteRenderer>();
|
||||
if(spriteRenderer != null){
|
||||
spriteRenderer.enabled = false;
|
||||
}
|
||||
player.position = newPosition;
|
||||
yield return new WaitForSeconds(0.3f);
|
||||
if(spriteRenderer != null){
|
||||
spriteRenderer.enabled = true;
|
||||
}
|
||||
onCooldown = true;
|
||||
yield return new WaitForSeconds(cooldownDuration);
|
||||
onCooldown = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10ac0a73b4ec786e2980bdbc87798553
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random=UnityEngine.Random; // To not confuse with System.Random
|
||||
|
||||
public class BulletHitEnemy : MonoBehaviour
|
||||
{
|
||||
public GameObject pickUpPrefab;
|
||||
private void Start(){
|
||||
// Destroy after 2s if we don't hit anything.
|
||||
Destroy(gameObject, 2f);
|
||||
}
|
||||
void OnCollisionEnter2D(Collision2D other){
|
||||
float dropChance = Random.value; // Generate random float between 0 and 1
|
||||
// If a bullet hits an enemy, destroy the enemy object and the bullet itself.
|
||||
if(other.gameObject.CompareTag("Enemy")){
|
||||
// Enemy has a 10% chance of dropping an item
|
||||
if (dropChance <= 0.1f)
|
||||
{
|
||||
Instantiate(pickUpPrefab, transform.position, Quaternion.identity);
|
||||
}
|
||||
Destroy(gameObject);
|
||||
other.gameObject.GetComponent<Helth>().TakeDamage(1);
|
||||
}
|
||||
// If a bullet hits an obstacle (walls..), just destroy the bullet.
|
||||
else if (other.gameObject.CompareTag("Obstacle")){
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bc7b72174fd331c1b12b718854a9173
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aec2ac7de6d4f2ee09ff97445cda975a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
public class IncreasedFirerate : MonoBehaviour
|
||||
{
|
||||
public float baseFirerate = 0.25f;
|
||||
public float firerateMultiplier = 5f;
|
||||
public int durationSeconds = 10;
|
||||
private Weapon weapon;
|
||||
|
||||
public void Initialize(Weapon playerWeapon)
|
||||
{
|
||||
weapon = playerWeapon;
|
||||
StartCoroutine(IncreaseFirerate());
|
||||
}
|
||||
|
||||
IEnumerator IncreaseFirerate()
|
||||
{
|
||||
weapon.SetCurrentFirerate(baseFirerate / firerateMultiplier);
|
||||
yield return new WaitForSeconds(durationSeconds);
|
||||
weapon.SetCurrentFirerate(baseFirerate);
|
||||
PickUp.isPickedRate = false;
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37d8f945cc83da577b6931428b205afd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
public class IncreasedMovement : MonoBehaviour
|
||||
{
|
||||
public int durationSeconds = 10; // How long the effect lasts.
|
||||
public float speedMultiplier = 1.5f; // How much faster the player moves.
|
||||
public PlayerController playerController;
|
||||
|
||||
private bool isMovementIncreased;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
StartCoroutine(IncreaseMovement());
|
||||
}
|
||||
IEnumerator IncreaseMovement()
|
||||
{
|
||||
isMovementIncreased = true;
|
||||
yield return new WaitForSeconds(durationSeconds);
|
||||
isMovementIncreased = false;
|
||||
PickUp.isPickedMovement = false;
|
||||
Destroy(this);
|
||||
}
|
||||
|
||||
public float GetCurrentSpeed()
|
||||
{
|
||||
return isMovementIncreased ? playerController.moveSpeed * speedMultiplier : playerController.moveSpeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 987d4ff26717c562bbba7a74e9b12643
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PickUp : MonoBehaviour
|
||||
{
|
||||
public static bool isPickedMovement = false;
|
||||
public static bool isPickedRate = false;
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (!other.gameObject.CompareTag("Player")) return;
|
||||
|
||||
// Generate a random number between 0 and 1 to determine the ability type
|
||||
var abilityType = Random.Range(0, 2);
|
||||
switch (abilityType)
|
||||
{
|
||||
case 0:
|
||||
if (!other.gameObject.GetComponent<Player.IncreasedMovement>())
|
||||
{
|
||||
Player.IncreasedMovement increasedMovementEffect = other.gameObject.AddComponent<Player.IncreasedMovement>();
|
||||
increasedMovementEffect.playerController = other.GetComponent<PlayerController>();
|
||||
isPickedMovement = true;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!other.gameObject.GetComponent<Player.IncreasedFirerate>())
|
||||
{
|
||||
Player.IncreasedFirerate increasedFirerateEffect = other.gameObject.AddComponent<Player.IncreasedFirerate>();
|
||||
Weapon weapon = other.gameObject.GetComponentInChildren<Weapon>();
|
||||
increasedFirerateEffect.Initialize(weapon);
|
||||
isPickedRate = true;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db7b0140a15c61e41a8f169dfaec24dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Player;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
// Movement
|
||||
public float moveSpeed;
|
||||
public Rigidbody2D rb;
|
||||
private Vector2 _moveDirection;
|
||||
private Teleport teleport;
|
||||
private IncreasedMovement increasedMovement;
|
||||
public static bool unlockedMultishot = false;
|
||||
public static bool unlockedTeleport = false;
|
||||
public static bool unlockedBomb = false;
|
||||
public static bool unlockedRun = false;
|
||||
private Vector2 _lookDirection;
|
||||
public static int deathAmount = 0;
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
moveSpeed = 5;
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
|
||||
increasedMovement.playerController = this;
|
||||
}
|
||||
|
||||
// Update is called once per frame, because of that we shouldn't do physics here.
|
||||
void Update()
|
||||
{
|
||||
ProcessInputs();
|
||||
FollowCamera();
|
||||
|
||||
if (increasedMovement == null )
|
||||
{
|
||||
increasedMovement = GetComponent<IncreasedMovement>();
|
||||
if (increasedMovement != null)
|
||||
{
|
||||
increasedMovement.playerController = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Called at fixed intervals instead of users frame rate -> Better for physics.
|
||||
private void FixedUpdate(){
|
||||
Move();
|
||||
AimDirection();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ProcessInputs(){
|
||||
float moveX = Input.GetAxisRaw("Horizontal"); // Raw gives u either 0 or 1.
|
||||
float moveY = Input.GetAxisRaw("Vertical");
|
||||
|
||||
_moveDirection = new Vector2(moveX, moveY);
|
||||
|
||||
// Convert mouse position into Unity coordinate system (World).
|
||||
if (Camera.main != null) _lookDirection = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
|
||||
}
|
||||
|
||||
void Move(){
|
||||
float actMoveSpeed = increasedMovement != null ? increasedMovement.GetCurrentSpeed() : moveSpeed;
|
||||
// Increase speed if shift is pressed or held.
|
||||
if(Input.GetKey(KeyCode.LeftShift) && unlockedRun){
|
||||
rb.velocity = new Vector2(_moveDirection.x * actMoveSpeed * 1.5f, _moveDirection.y * actMoveSpeed * 1.5f);
|
||||
}
|
||||
else{
|
||||
rb.velocity = new Vector2(_moveDirection.x * actMoveSpeed, _moveDirection.y * actMoveSpeed);
|
||||
}
|
||||
|
||||
if (teleport == null) teleport = gameObject.GetComponent<Teleport>();
|
||||
if (Input.GetKey(KeyCode.Q) && teleport != null && !teleport.onCooldown && unlockedTeleport){
|
||||
if (FindAnyObjectByType<AudioManager>() != null)
|
||||
{
|
||||
FindObjectOfType<AudioManager>().Play("TeleportSound");
|
||||
}
|
||||
|
||||
teleport.TeleportPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
void AimDirection(){
|
||||
// Get direction from player to mouse position.
|
||||
Vector2 lookDir = _lookDirection - rb.position;
|
||||
// Convert direction to angle.
|
||||
float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
|
||||
// Rotate player to look at mouse position.
|
||||
rb.rotation = angle;
|
||||
}
|
||||
void FollowCamera(){
|
||||
var position = transform.position;
|
||||
if (Camera.main != null) Camera.main.transform.position = new Vector3(position.x, position.y, -10);
|
||||
}
|
||||
|
||||
// Used for collision with a gameobject that changes scenes
|
||||
void OnCollisionEnter2D(Collision2D other) {
|
||||
if (other.gameObject.CompareTag("NextScene")){
|
||||
ChangeScene.Instance.moveToNextScene();
|
||||
}
|
||||
if (other.gameObject.CompareTag("PreviousScene")){
|
||||
ChangeScene.Instance.moveToPreviousScene();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71c420adbe32086449c06741fd353238
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,116 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Player;
|
||||
using UnityEngine;
|
||||
public class Weapon : MonoBehaviour
|
||||
{
|
||||
private string fireButton = "Fire1";
|
||||
public GameObject bulletPrefab;
|
||||
public Transform firePoint;
|
||||
public float bulletForce = 20f;
|
||||
private float nextFireTime = 0f;
|
||||
private float currentFirerate;
|
||||
private IncreasedFirerate increasedFirerate;
|
||||
private bool bombOnCooldown = false;
|
||||
public GameObject bombPrefab;
|
||||
private void EquipIncreasedFirerate()
|
||||
{
|
||||
increasedFirerate = GetComponent<IncreasedFirerate>();
|
||||
if (increasedFirerate != null)
|
||||
{
|
||||
increasedFirerate.enabled = true;
|
||||
}
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
if (firePoint == null)
|
||||
{
|
||||
firePoint = transform.GetChild(0).GetComponent<Transform>(); // Assuming the firePoint is the first child of the Weapon object
|
||||
}
|
||||
currentFirerate = 0.25f; // Higher number = slower firerate
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
EquipIncreasedFirerate();
|
||||
if (Input.GetButton(fireButton) && Time.time >= nextFireTime)
|
||||
{
|
||||
StartCoroutine(InstantiateBullet("bullet"));
|
||||
nextFireTime = Time.time + currentFirerate;
|
||||
}
|
||||
else if(Input.GetKeyDown(KeyCode.Space)){
|
||||
StartCoroutine(InstantiateBullet("bomb"));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator InstantiateBullet(string type)
|
||||
{
|
||||
if (PlayerController.unlockedMultishot && type != "bomb")
|
||||
{
|
||||
// Create three bullets from the Bullet Prefab
|
||||
GameObject bullet1 = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
|
||||
GameObject bullet2 = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
|
||||
GameObject bullet3 = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
|
||||
|
||||
if (FindAnyObjectByType<AudioManager>() != null)
|
||||
{
|
||||
FindObjectOfType<AudioManager>().Play("MultiSound");
|
||||
}
|
||||
|
||||
// Add velocity to the middle bullet
|
||||
Rigidbody2D rb1 = bullet1.GetComponent<Rigidbody2D>();
|
||||
rb1.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
|
||||
|
||||
// Add velocity to the right bullet
|
||||
Rigidbody2D rb2 = bullet2.GetComponent<Rigidbody2D>();
|
||||
rb2.AddForce(Quaternion.Euler(0, 0, -25) * firePoint.up * bulletForce, ForceMode2D.Impulse);
|
||||
|
||||
// Add velocity to the left bullet
|
||||
Rigidbody2D rb3 = bullet3.GetComponent<Rigidbody2D>();
|
||||
rb3.AddForce(Quaternion.Euler(0, 0, 25) * firePoint.up * bulletForce, ForceMode2D.Impulse);
|
||||
|
||||
}
|
||||
else if (type == "bomb" && !bombOnCooldown && PlayerController.unlockedBomb)
|
||||
{
|
||||
bombOnCooldown = true;
|
||||
GameObject bombInstance = Instantiate(bombPrefab, firePoint.position, firePoint.rotation);
|
||||
Rigidbody2D rb = bombInstance.GetComponent<Rigidbody2D>();
|
||||
rb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
|
||||
if (FindAnyObjectByType<AudioManager>() != null)
|
||||
{
|
||||
FindObjectOfType<AudioManager>().Play("BombSound");
|
||||
}
|
||||
|
||||
|
||||
yield return new WaitForSeconds(4);
|
||||
|
||||
|
||||
|
||||
bombOnCooldown = false;
|
||||
}
|
||||
|
||||
else if(type == "bullet" && !PlayerController.unlockedMultishot)
|
||||
{
|
||||
// Create a single bullet from the Bullet Prefab
|
||||
GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
|
||||
|
||||
if(FindAnyObjectByType<AudioManager>() != null)
|
||||
{
|
||||
FindObjectOfType<AudioManager>().Play("ShootSound");
|
||||
}
|
||||
|
||||
// Add velocity to the bullet
|
||||
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
|
||||
rb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
|
||||
|
||||
public void SetCurrentFirerate(float newFirerate)
|
||||
{
|
||||
currentFirerate = newFirerate;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e0862cff17b2b52f90faa43ccd5e74f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -30000
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e101f355495808b48a9fd43b234b8116
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimateTiles : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject tilemap;
|
||||
public float timeToToggle = 5;
|
||||
public float currentTime = 0;
|
||||
|
||||
public new bool enabled = true;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
currentTime += Time.deltaTime;
|
||||
if (currentTime >= timeToToggle){
|
||||
currentTime = 0;
|
||||
ToggleTile();
|
||||
}
|
||||
}
|
||||
|
||||
void ToggleTile(){
|
||||
enabled = !enabled;
|
||||
tilemap.gameObject.SetActive(enabled);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9f1172270a07b746b83e1908fcb6b9d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Tilemaps;
|
||||
|
||||
public class BreakArea : MonoBehaviour
|
||||
{
|
||||
private Tilemap tilemap;
|
||||
|
||||
void Start()
|
||||
{
|
||||
tilemap = GetComponent<Tilemap>();
|
||||
}
|
||||
// On collision with a bullet, destroy the tile
|
||||
private void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Bullet"))
|
||||
{
|
||||
Vector3 hitPosition = Vector3.zero;
|
||||
|
||||
foreach (ContactPoint2D hit in collision.contacts)
|
||||
{
|
||||
hitPosition.x = hit.point.x - 0.01f * hit.normal.x;
|
||||
hitPosition.y = hit.point.y - 0.01f * hit.normal.y;
|
||||
hitPosition.z = -1;
|
||||
|
||||
tilemap.SetTile(tilemap.WorldToCell(hitPosition), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e41c622ca4d3d64a9a7e4f5376031d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class ChangeScene : MonoBehaviour
|
||||
{
|
||||
public static ChangeScene Instance;
|
||||
|
||||
private string nextScene;
|
||||
private string previousScene;
|
||||
|
||||
private void Awake() {
|
||||
|
||||
if (Instance == null){
|
||||
Instance = this;
|
||||
}
|
||||
else if (Instance != this){
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void Start() {
|
||||
// Gets the current scene name
|
||||
Scene scene = SceneManager.GetActiveScene();
|
||||
if (scene.name == "demoLevel"){
|
||||
nextScene = "Hall1";
|
||||
previousScene = null;
|
||||
}
|
||||
else if (scene.name == "hall1"){
|
||||
nextScene = "BossRoom1";
|
||||
previousScene = "demoLevel";
|
||||
}
|
||||
else if (scene.name == "level2start"){
|
||||
nextScene = "level2hall";
|
||||
previousScene = null;
|
||||
}
|
||||
else if (scene.name == "level2hall"){
|
||||
nextScene = "level2boss";
|
||||
previousScene = null;
|
||||
}
|
||||
else if (scene.name == "level3start"){
|
||||
nextScene = "level3hall";
|
||||
previousScene = null;
|
||||
}
|
||||
else if (scene.name == "level3hall"){
|
||||
nextScene = "level3boss";
|
||||
previousScene = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void moveToNextScene(){
|
||||
SceneManager.LoadScene(nextScene);
|
||||
}
|
||||
|
||||
public void moveToPreviousScene(){
|
||||
SceneManager.LoadScene(previousScene);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0bea73a56758b340b26616b50f4c152
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SceneRotator : MonoBehaviour
|
||||
{
|
||||
public float rotationSpeed = 10f;
|
||||
|
||||
void Update()
|
||||
{
|
||||
float rotation = rotationSpeed * Time.deltaTime;
|
||||
transform.Rotate(0, 0, rotation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e13147faa8eccde42bfd7362ed61566e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user