56 lines
1.2 KiB
C#
56 lines
1.2 KiB
C#
|
|
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
|
|
}
|
|
}
|
|
|