2019-10-05 09:48:36 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class SpawnOnMouseClick : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
[Header("Config")]
|
2019-10-06 15:44:41 +00:00
|
|
|
|
public GameController gameController;
|
2019-10-05 09:48:36 +00:00
|
|
|
|
public int mouseButton;
|
2019-10-06 15:44:41 +00:00
|
|
|
|
public int spawnedTier;
|
|
|
|
|
public int spawnCount;
|
|
|
|
|
public float appliedForce;
|
|
|
|
|
|
|
|
|
|
protected void Awake() {
|
|
|
|
|
gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
|
|
|
|
|
}
|
2019-10-05 09:48:36 +00:00
|
|
|
|
|
|
|
|
|
protected Vector3 GetWorldMousePosition() {
|
|
|
|
|
return Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2019-10-06 13:04:50 +00:00
|
|
|
|
if(Input.GetMouseButtonDown(mouseButton)) {
|
2019-10-05 09:48:36 +00:00
|
|
|
|
Vector3 mousePosition = GetWorldMousePosition();
|
2019-10-06 15:44:41 +00:00
|
|
|
|
for(int i = 0; i < spawnCount; i++) {
|
|
|
|
|
GameObject particleObject = Instantiate(gameController.particlePrefab, new Vector3(mousePosition.x, mousePosition.y, 0f), Quaternion.identity);
|
|
|
|
|
Particle particle = particleObject.GetComponent<Particle>();
|
|
|
|
|
particle.Tier = spawnedTier;
|
|
|
|
|
Vector2 direction = new Vector2(Random.value - 0.5f, Random.value - 0.5f).normalized;
|
|
|
|
|
particle.rigidbody.AddForce(direction * appliedForce);
|
|
|
|
|
}
|
2019-10-05 09:48:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|