Beispiel #1
0
    // Use this for initialization
    void Awake()
    {
        gameCamera         = GameObject.Find("Main Camera").GetComponent <Camera>();
        ship               = new Ship(shipType, maxHealth, shipSpeed);
        ship.dodgeSpeed    = dodgeSpeed;
        ship.dodgeLength   = dodgeLength;
        ship.weapons [0]   = Weapon.createBasicEnemyWeapon();
        ship.isComponent   = isComponent;
        ship.componentType = componentType;
        //instantiate weapons based on ship type

        switch (shipType)
        {
        case shipType.fighter:
            break;

        case shipType.frigate:
            ship.weapons [0] = Weapon.createFrigateSpreadWeapon();
            break;
        }

        if (componentCount > 0)
        {
            //spawn in components

            string resourcePath = "";

            switch (shipType)
            {
            case shipType.frigate:
                resourcePath = "frigate_components/";
                break;
            }

            //right now we only support 2 components per ship - 1 left and 1 right
            var           values = componentType.GetValues(typeof(componentType));
            componentType left   = (componentType)values.GetValue(Random.Range(0, values.Length));
            componentType right  = (componentType)values.GetValue(Random.Range(0, values.Length));

            //totally janky
            Object LeftComponent = Resources.Load(resourcePath + "left_" + left.ToString());
            components.Add(LeftComponent);

            Object RightComponent = Resources.Load(resourcePath + "right_" + right.ToString());
            components.Add(RightComponent);

            foreach (Object component in components)
            {
                //initialize component properties
                GameObject newComponent = Instantiate(component) as GameObject;
                newComponent.GetComponent <EnemyFighterAI> ().isComponent = true;
                newComponent.transform.parent = this.transform;

                switch (newComponent.GetComponent <EnemyFighterAI> ().componentType)
                {
                case componentType.shield:
                    shipType   type      = this.ship.shipType;
                    Object     shield    = null;
                    GameObject newShield = null;

                    switch (type)
                    {
                    case shipType.frigate:
                        shield = Resources.Load(resourcePath + "shield");
                        break;
                    }

                    newShield = Instantiate(shield) as GameObject;
                    newShield.transform.parent = newComponent.transform;
                    //set sheild and generator to both have null weapons
                    newShield.GetComponent <EnemyFighterAI> ().ship.weapons = null;
                    this.weapons = null;

                    break;

                case componentType.missile:
                    newComponent.GetComponent <EnemyFighterAI> ().ship.weapons [0] = Weapon.createBasicEnemymissile();
                    break;

                case componentType.rail:
                    newComponent.GetComponent <EnemyFighterAI> ().ship.weapons [0] = Weapon.createBasicEnemyRail();
                    break;
                }

                //if its a right component change the weapon offset to be -x
                if (newComponent.name.Contains("left") && newComponent.GetComponent <EnemyFighterAI> ().ship.weapons.Length > 0)
                {
                    foreach (Weapon weapon in newComponent.GetComponent <EnemyFighterAI> ().ship.weapons)
                    {
                        if (weapon != null)
                        {
                            foreach (FireStream firestream in weapon.fireStreams)
                            {
                                firestream.offset = new Vector3(-firestream.offset.x, firestream.offset.y);
                            }
                        }
                    }
                }
            }
        }
    }