Beispiel #1
0
    //private List<ObjectModel> players = new List<ObjectModel>();
    void Awake()
    {
        this.gameObject.AddComponent<PlayerController>();
        playerController = GetComponent<PlayerController>();
        PlayerBehaviour player = new DefaultPlayer();
        player.SetModel(ItemDatabase.GetItemByName("Aero").gameModel);
        Weapon weaponDefault = new AeroWeapon();
        Bullet bullet = new PlazmaBullet();
        bullet.SetModel(ItemDatabase.GetItemByName("plazmabullet").gameModel);
        bullet.SetType(BulletType.PLAYER);
        weaponDefault.SetWeaponBullet(bullet);
        //weaponDefault.SetWeaponBullet(ItemDatabase.GetItemByName("plazmabullet").gameModel);
        player.AddWeapon(weaponDefault);
        playerController.AddPlayer(player, false);

        UnityEngine.Cursor.visible = false;
        //SpawnPlayer
        //playerSpawn = new Vector3(0, -3, 0);
        //GameObject player = (GameObject)Instantiate(ItemDatabase.GetItemByName("Aero").gameModel, playerSpawn, ItemDatabase.GetItemByName("Aero").gameModel.transform.rotation)
        //player.AddComponent<AeroWeapon>();

        //player.GetShipModel().AddComponent<AeroWeapon>();
        //player.GetShipModel().GetComponent<AeroWeapon>().SetWeaponBullet(ItemDatabase.GetItemByName("PlazmaBullet"));

        Vector3 bottomLeft = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, Camera.main.nearClipPlane));
        Vector3 topRight = Camera.main.ViewportToWorldPoint(new Vector3(1, 1, Camera.main.nearClipPlane));
        screenWidth = topRight.x - bottomLeft.x;
        screenHeight = topRight.y - bottomLeft.y;

        levelRows = File.ReadAllLines("Assets/Resources/LevelTexts/Level1.txt");
        dbItems = ItemDatabase.GetItems();
        //delay = Random.Range(minDelay, maxDelay) * Time.deltaTime;
        delay = spawnDelay * Time.deltaTime;
    }
Beispiel #2
0
    public void Attack(Vector3 direction, Vector3 pos)
    {
        for (int i = 0; i < bullets.Count; i++) {
            if (bullets[i].GetModel() != null) {
                if (Vector3.Distance(pos, bullets[i].GetModel().transform.position) > 8) {
                    GameObject.Destroy(bullets[i].GetModel());
                    bullets.Remove(bullets[i]);
                }
            } else {
                bullets.Remove(bullets[i]);
            }
        }
        //Debug.Log("Bullet Count: " + bullets.Count);
        if (delay <= 0 && bullets.Count == 0) {
            Bullet leftBullet = new PlazmaBullet();
            leftBullet.SetModel((GameObject)GameObject.Instantiate(bullet.GetModel(), new Vector3(pos.x - 0.25f, pos.y, pos.z), bullet.GetModel().transform.rotation));
            leftBullet.GetModel().GetComponent<Rigidbody>().AddForce(direction * bulletVelocity * Time.deltaTime);
            leftBullet.SetType(BulletType.PLAYER);
            bullets.Add(leftBullet);
            leftBullet.GetModel().AddComponent<CollisionController>();
            leftBullet.GetModel().GetComponent<CollisionController>().SetObject(leftBullet);
            //GarbageCollector.AddGameObject(leftBullet);

            Bullet rightBullet = new PlazmaBullet();
            rightBullet.SetModel((GameObject)GameObject.Instantiate(bullet.GetModel(), new Vector3(pos.x + 0.25f, pos.y, pos.z), bullet.GetModel().transform.rotation));
            rightBullet.GetModel().GetComponent<Rigidbody>().AddForce(direction * bulletVelocity * Time.deltaTime);
            rightBullet.SetType(BulletType.PLAYER);
            bullets.Add(rightBullet);
            rightBullet.GetModel().AddComponent<CollisionController>();
            rightBullet.GetModel().GetComponent<CollisionController>().SetObject(rightBullet);
            //GarbageCollector.AddGameObject(rightBullet);

            attackEnabled = false;
            delay = attackDelay;
        } else if (delay > 0) {
            delay--;
        }
    }