using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class App : MonoBehaviour
{
public Ship ship;
public Button CreateEnemy;
public Button CreateShip;
private bool enemyExist = false;
private GameObject enemyPrefab;
public static GameObject bulletPrefab;
public static GameObject explosion;
private GameObject shipPrefab;
// Start is called before the first frame update
private void Awake()
{
}
void Start()
{
CreateShip.onClick.AddListener(() =>
{
{
GameObject shipGO = new GameObject("Ship");
ship = shipGO.AddComponent<Ship>();
var model = Instantiate(shipPrefab);
ship.transform.position = new Vector3(0, -1.237f, -1.7045f);
model.transform.SetParent(shipGO.transform, false);
}
});
CreateEnemy.onClick.AddListener(() => //enemy 생성
{
if(!enemyExist)
{
float x = 1;
for (int i = 0; i<5; i++)
{
GameObject enemyGO = new GameObject("enemy");
Enemy enemy = enemyGO.AddComponent<Enemy>();
enemyGO.transform.position = new Vector3(x, 3.38f, -1.7045f);
var model = Instantiate(enemyPrefab);
model.transform.SetParent(enemyGO.transform, false);
x -= 0.5f;
}
enemyExist = true;
}
});
}
// Update is called once per frame
void Update()
{
{
enemyExist = false;
}
if(ship != null)
{
{
if (ship.transform.position.x >= -1.96f)
{
ship.transform.position
+= Vector3.left * 2 * Time.deltaTime;
}
}
{
if (ship.transform.position.x <= 1.96f)
}
{
if (ship.transform.position.y <= 4.4f)
ship.transform.position
+= Vector3.up * 2 * Time.deltaTime;
}
{
if (ship.transform.position.y >= -1.7f)
ship.transform.position
+= Vector3.down * 2 * Time.deltaTime;
}
{
GameObject bulletGO = new GameObject("Bullet");
bulletGO.transform.position = ship.bulletInitPoint.transform.position;
Bullet bullet = bulletGO.AddComponent<Bullet>();
var model = Instantiate(App.bulletPrefab);
model.transform.SetParent(bulletGO.transform, false);
}
}
}
}