UI update 02
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace KD.Destro2D{
|
||||
public class BasicMissile : MonoBehaviour
|
||||
{
|
||||
public GameObject DestructionObject;
|
||||
public GameObject effect;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
Destroy(this.gameObject,4f);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
Vector2 hitPoint = collision.contacts[0].point;
|
||||
if(this!= null){
|
||||
Instantiate(DestructionObject,hitPoint,Quaternion.identity);
|
||||
Instantiate(effect,hitPoint,Quaternion.identity);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0bc49a307487e054ea6a29c582421a68
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 358408
|
||||
packageName: Destro 2D - Dynamic Sprite Destruction
|
||||
packageVersion: 1.0.3
|
||||
assetPath: Assets/Destro2DMain/Demos/Prefabs/Scripts/BasicMissile.cs
|
||||
uploadId: 925032
|
||||
@@ -0,0 +1,82 @@
|
||||
using UnityEngine;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
namespace KD.Destro2D{
|
||||
public class BasicPlayerControl2D : MonoBehaviour
|
||||
{
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
public InputActionAsset inputActions;
|
||||
public float bulletCD;
|
||||
InputAction move;
|
||||
InputAction missileAttack;
|
||||
InputAction bulletAttack;
|
||||
Rigidbody2D rb;
|
||||
public float speed;
|
||||
Vector2 lookDirn;
|
||||
Vector2 dirn;
|
||||
public GameObject missilePrefab;
|
||||
public GameObject bulletPrefab;
|
||||
public float missileSpeed;
|
||||
public float shootOffset;
|
||||
float t;
|
||||
void OnEnable()
|
||||
{
|
||||
move = inputActions.FindAction("Player/Move",true);
|
||||
missileAttack = inputActions.FindAction("Player/AltAttack",true);
|
||||
bulletAttack = inputActions.FindAction("Player/Attack",true);
|
||||
missileAttack.Enable();
|
||||
bulletAttack.Enable();
|
||||
move.Enable();
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
missileAttack.performed += _ => ShootMissile(missilePrefab);
|
||||
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
missileAttack.Disable();
|
||||
bulletAttack.Disable();
|
||||
move.Disable();
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
t+=Time.deltaTime;
|
||||
Move();
|
||||
Look();
|
||||
if(bulletAttack.IsPressed()){
|
||||
if(t < bulletCD) return;
|
||||
ShootMissile(bulletPrefab);
|
||||
t = 0;
|
||||
}
|
||||
}
|
||||
void FixedUpdate()
|
||||
{
|
||||
rb.AddForce(dirn);
|
||||
}
|
||||
void ShootMissile(GameObject prefab)
|
||||
{
|
||||
float angle = Mathf.Atan2(lookDirn.y,lookDirn.x) * Mathf.Rad2Deg;
|
||||
Quaternion missileRotn = Quaternion.AngleAxis(angle,transform.forward);
|
||||
Rigidbody2D missile = Instantiate(prefab,(Vector2)transform.position + lookDirn.normalized * shootOffset,missileRotn).GetComponent<Rigidbody2D>();
|
||||
missile.AddForce(lookDirn.normalized * missileSpeed);
|
||||
}
|
||||
void Look()
|
||||
{
|
||||
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Mouse.current.position.ReadValue());
|
||||
mousePos.z = transform.position.z;
|
||||
lookDirn = mousePos - transform.position;
|
||||
}
|
||||
void Move()
|
||||
{
|
||||
float dirval = move.ReadValue<float>();
|
||||
dirn = transform.right * dirval * speed;
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 320edd842814fe243b374e3ff7854d70
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 358408
|
||||
packageName: Destro 2D - Dynamic Sprite Destruction
|
||||
packageVersion: 1.0.3
|
||||
assetPath: Assets/Destro2DMain/Demos/Prefabs/Scripts/BasicPlayerControl2D.cs
|
||||
uploadId: 925032
|
||||
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace KD.Destro2D{
|
||||
public class BasicPlayerFollow : MonoBehaviour
|
||||
{
|
||||
public Transform player;
|
||||
public float dist = -10;
|
||||
public float offsetY = 2;
|
||||
public float speed = 5;
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void LateUpdate()
|
||||
{
|
||||
Vector3 targetpos = new Vector3(player.position.x,player.position.y + offsetY,dist);
|
||||
transform.position = Vector3.Lerp(transform.position,targetpos,speed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b50307b24efad1f4d8ca6963b3453c0d
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 358408
|
||||
packageName: Destro 2D - Dynamic Sprite Destruction
|
||||
packageVersion: 1.0.3
|
||||
assetPath: Assets/Destro2DMain/Demos/Prefabs/Scripts/BasicPlayerFollow.cs
|
||||
uploadId: 925032
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace KD.Destro2D{
|
||||
|
||||
public class DoBasicDestruction : MonoBehaviour
|
||||
{
|
||||
[SerializeReference]
|
||||
public List<Destruction> destructions = new();
|
||||
[Header("Burn colors correspond to destructions in order, make sure to have SAME COUNT")]
|
||||
public List<Color> burncolors = new();
|
||||
public float radius = 1f;
|
||||
public bool doMainDestruction = false;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
Collider2D[] col = Physics2D.OverlapCircleAll(transform.position,radius);
|
||||
foreach(Collider2D c in col)
|
||||
{
|
||||
if(c.TryGetComponent<Destro2DMain>(out var d)){
|
||||
//important to setup when dealing with other object
|
||||
for(int i = 0; i < destructions.Count; i++)
|
||||
{
|
||||
var dest = destructions[i];
|
||||
var color = burncolors[i];
|
||||
dest.SetupWithColor(c.gameObject,color);
|
||||
}
|
||||
d.DynamicDestroyWorld(transform.position,destructions);
|
||||
if(doMainDestruction) d.DynamicDestroyWorld(transform.position);
|
||||
}
|
||||
|
||||
}
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 468637d39f5b1c444a55bf2202d62fa9
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 358408
|
||||
packageName: Destro 2D - Dynamic Sprite Destruction
|
||||
packageVersion: 1.0.3
|
||||
assetPath: Assets/Destro2DMain/Demos/Prefabs/Scripts/DoBasicDestruction.cs
|
||||
uploadId: 925032
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
namespace KD.Destro2D{
|
||||
public class DoExplosion : MonoBehaviour
|
||||
{
|
||||
public float radiusCore = 0f;
|
||||
public float radiusOuter = 1f;
|
||||
public float noiseScale = 20f;
|
||||
public float thickness = 0.12f;
|
||||
public float force = 100f;
|
||||
void OnEnable()
|
||||
{
|
||||
Collider2D[] col = Physics2D.OverlapCircleAll(transform.position,radiusOuter);
|
||||
foreach(Collider2D c in col)
|
||||
{
|
||||
if(c.TryGetComponent<Destro2DMain>(out var d)){
|
||||
d.DynamicFracture(transform.position,radiusCore,radiusOuter,noiseScale,thickness,5);
|
||||
}
|
||||
|
||||
}
|
||||
StartCoroutine(AddForce());
|
||||
}
|
||||
IEnumerator AddForce()
|
||||
{
|
||||
//delay for the chunks to actually split
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
//detect again, then add force
|
||||
Collider2D[] col = Physics2D.OverlapCircleAll(transform.position,radiusOuter);
|
||||
foreach(Collider2D c in col)
|
||||
{
|
||||
if(c.TryGetComponent<SplitHandler>(out var s) && c.TryGetComponent<Rigidbody2D>(out var rb))
|
||||
{
|
||||
Vector2 worldChunkCentre = c.transform.TransformPoint(s.chunkCentre);
|
||||
Vector2 dir = worldChunkCentre - (Vector2)transform.position;
|
||||
rb.AddForce(dir.normalized * force);
|
||||
}
|
||||
}
|
||||
Destroy(this.gameObject);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f890bf06646f284484b476fbe1d0331
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 358408
|
||||
packageName: Destro 2D - Dynamic Sprite Destruction
|
||||
packageVersion: 1.0.3
|
||||
assetPath: Assets/Destro2DMain/Demos/Prefabs/Scripts/DoExplosion.cs
|
||||
uploadId: 925032
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace KD.Destro2D{
|
||||
public class DoGrowingDestruction : MonoBehaviour
|
||||
{
|
||||
public float radius = 1f;
|
||||
void OnEnable()
|
||||
{
|
||||
Collider2D[] col = Physics2D.OverlapCircleAll(transform.position,radius);
|
||||
foreach(Collider2D c in col)
|
||||
{
|
||||
if(c.TryGetComponent<Destro2DMain>(out var d)){
|
||||
d.DynamicDestroyWorld(c.ClosestPoint(transform.position));
|
||||
}
|
||||
|
||||
}
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5857f8bde12c0bc4c95d504a77507c78
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 358408
|
||||
packageName: Destro 2D - Dynamic Sprite Destruction
|
||||
packageVersion: 1.0.3
|
||||
assetPath: Assets/Destro2DMain/Demos/Prefabs/Scripts/DoGrowingDestruction.cs
|
||||
uploadId: 925032
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
|
||||
namespace KD.Destro2D{
|
||||
public class SpawnDestruction : MonoBehaviour
|
||||
{
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
public InputActionAsset inputActions;
|
||||
public float interval = 0.1f;
|
||||
public GameObject destructionObject;
|
||||
InputAction click;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
|
||||
click = inputActions.FindAction("Player/Attack",true);
|
||||
click.Enable();
|
||||
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
click.Disable();
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
StartCoroutine(SpawnDestructionObject(interval));
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
IEnumerator SpawnDestructionObject(float interval)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if(click.IsPressed()){
|
||||
|
||||
Vector2 mouseScreen = Mouse.current.position.ReadValue();
|
||||
Vector3 mousepos = Camera.main.ScreenToWorldPoint(mouseScreen);
|
||||
mousepos.z = 0f;
|
||||
Instantiate(destructionObject,mousepos,Quaternion.identity);
|
||||
|
||||
}
|
||||
yield return new WaitForSeconds(interval);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1f4491c42c8e4741a70502de1fcf00c
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 358408
|
||||
packageName: Destro 2D - Dynamic Sprite Destruction
|
||||
packageVersion: 1.0.3
|
||||
assetPath: Assets/Destro2DMain/Demos/Prefabs/Scripts/SpawnDestruction.cs
|
||||
uploadId: 925032
|
||||
Reference in New Issue
Block a user