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-07 11:44:26 +00:00
|
|
|
|
public int mouseButton = 0;
|
|
|
|
|
public int spawnedTier = 0;
|
|
|
|
|
public int spawnCount = 1;
|
|
|
|
|
public float appliedForce = 0.1f;
|
|
|
|
|
|
2019-10-14 23:36:48 +00:00
|
|
|
|
protected Camera camera;
|
2019-10-07 11:44:26 +00:00
|
|
|
|
protected GameController gameController;
|
2019-10-06 15:44:41 +00:00
|
|
|
|
|
|
|
|
|
protected void Awake() {
|
|
|
|
|
gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
|
2019-10-14 23:36:48 +00:00
|
|
|
|
camera = GetComponent<Camera>();
|
2019-10-06 15:44:41 +00:00
|
|
|
|
}
|
2019-10-05 09:48:36 +00:00
|
|
|
|
|
2019-10-14 23:36:48 +00:00
|
|
|
|
protected void SpawnAtPosition(Vector3 position) {
|
|
|
|
|
if(gameController.blackHole == null) {
|
|
|
|
|
gameController.blackHole = Instantiate(gameController.blackHolePrefab, new Vector3(position.x, position.y, 0f), Quaternion.identity).GetComponent<BlackHole>();
|
|
|
|
|
gameController.tutorial.Step2();
|
|
|
|
|
gameController.musicManager.UpdateLayers(-1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for(int i = 0; i < spawnCount; i++) {
|
|
|
|
|
GameObject particleObject = Instantiate(gameController.particlePrefab, new Vector3(position.x, position.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
|
|
|
|
}
|
|
|
|
|
|
2019-10-07 15:50:34 +00:00
|
|
|
|
protected void Update()
|
2019-10-05 09:48:36 +00:00
|
|
|
|
{
|
2019-10-14 23:36:48 +00:00
|
|
|
|
bool canSpawn = !gameController.upgradePanel.gameObject.activeSelf;
|
|
|
|
|
if(Application.platform == RuntimePlatform.Android) {
|
|
|
|
|
foreach(Touch touch in Input.touches) {
|
|
|
|
|
if(touch.phase == TouchPhase.Began) {
|
|
|
|
|
SpawnAtPosition(camera.ScreenToWorldPoint(touch.position));
|
2019-10-07 20:02:46 +00:00
|
|
|
|
}
|
2019-10-06 15:44:41 +00:00
|
|
|
|
}
|
2019-10-05 09:48:36 +00:00
|
|
|
|
}
|
2019-10-14 23:36:48 +00:00
|
|
|
|
else {
|
|
|
|
|
if(Input.GetMouseButtonDown(mouseButton)) {
|
|
|
|
|
SpawnAtPosition(camera.ScreenToWorldPoint(Input.mousePosition));
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-05 09:48:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|