1
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class BoxesSpawner : MonoBehaviour
|
||||
{
|
||||
public int num;
|
||||
public float maxSize;
|
||||
public float minSize;
|
||||
public GameObject boxPrefab;
|
||||
public List<Color> colors;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
var box = Instantiate(boxPrefab, Random.insideUnitCircle * 5, Quaternion.identity);
|
||||
box.GetComponent<SpriteRenderer>().color = colors[Random.Range(0, colors.Count)];
|
||||
box.transform.localScale = Vector3.one * Random.Range(minSize, maxSize);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.R))
|
||||
{
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2763ae511eef4094db911dd5324f1d10
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Explosion : MonoBehaviour
|
||||
{
|
||||
public float force;
|
||||
public GameObject particles;
|
||||
|
||||
public void Explode()
|
||||
{
|
||||
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, 5);
|
||||
Instantiate(particles, transform);
|
||||
foreach (var collider in colliders)
|
||||
{
|
||||
if (collider.GetComponent<Rigidbody2D>() != null)
|
||||
{
|
||||
Vector2 vec = collider.transform.position - transform.position;
|
||||
float mag = vec.magnitude;
|
||||
vec.Normalize();
|
||||
collider.GetComponent<Rigidbody2D>().
|
||||
AddForce(vec * force * Mathf.Clamp01(1 / mag), ForceMode2D.Impulse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b51bccceed685774f8cc239b2edbfc65
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
// Don't forget to add this.
|
||||
using CameraShake;
|
||||
|
||||
public class ExplosionTrigger : MonoBehaviour
|
||||
{
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Mouse0))
|
||||
{
|
||||
FindObjectOfType<Explosion>().Explode();
|
||||
|
||||
// Shaking the camera.
|
||||
CameraShaker.Presets.ShortShake2D();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02433c241d65a1f44b7df4ddc09cccb4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user