AddEnemy() public method

public AddEnemy ( GameObject enemy ) : GameObject
enemy GameObject
return GameObject
Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if (roomCont != null && flag == 0)
        {
            flag   = 1;
            lastHP = this.gameObject.GetComponent <EnemyHealth> ().startingHealth;
            for (int i = 0; i < quantPerWave; i++)
            {
                GameObject enemy = roomCont.AddEnemy(ghost);
                ghosts.Add(enemy);
                Debug.Log("Hit!");
            }
        }

        if (timer >= timeBetweenSwaps)
        {
            timer = 0f;
            foreach (GameObject ghost in ghosts)
            {
                if (ghost != null)
                {
                    if (roomCont == null)
                    {
                        Debug.Log(";_;");
                    }
                    GameObject chosenCell = roomCont.freeCells [Random.Range(0, roomCont.freeCells.Count)];
                    ghost.GetComponent <AIPath>().target = chosenCell.transform;
                    Debug.Log("Swapping paths!");
                }
            }
        }

        if (flag == 1 && (this.gameObject.GetComponent <EnemyHealth> ().currentHealth != lastHP))
        {
            GameObject player = GameObject.FindWithTag("Player");
            Vector3    temp   = player.transform.rotation * Vector3.forward * -1;
            player.GetComponent <Rigidbody>().AddForce(temp * 3000);
            foreach (GameObject ghost in ghosts)
            {
                if (ghost != null && ghost.tag != "Boss")
                {
                    Destroy(ghost);
                    Debug.Log("DIE!");
                }
            }
            this.gameObject.GetComponent <EnemySpinShot>().shoot = 1;
            lastHP = this.gameObject.GetComponent <EnemyHealth> ().currentHealth;
            this.gameObject.GetComponent <AIPath>().canMove = false;
            flag = 2;
        }

        if (flag == 2 && (lastHP != this.gameObject.GetComponent <EnemyHealth> ().currentHealth))
        {
            flag   = 1;
            lastHP = this.gameObject.GetComponent <EnemyHealth> ().currentHealth;
            this.gameObject.GetComponent <AIPath>().canMove      = true;
            ghost.GetComponent <AIPath>().canMove                = true;
            this.gameObject.GetComponent <EnemySpinShot>().shoot = 0;
            for (int i = 0; i < quantPerWave; i++)
            {
                GameObject enemy = roomCont.AddEnemy(ghost);
                ghosts.Add(enemy);
                Vector3 temppos;
                temppos = this.gameObject.transform.position;
                this.gameObject.transform.position = enemy.transform.position;
                enemy.transform.position           = temppos;
            }
        }
    }
Ejemplo n.º 2
0
Archivo: Configs.cs Proyecto: JvJ/CotWM
    /// <summary>
    /// Overlay the specified roomControl, room and config onto the room control.
    /// </summary>
    /// <param name='roomControl'>
    /// Room control.
    /// </param>
    /// <param name='room'>
    /// Room.
    /// </param>
    /// <param name='config'>
    /// Config.
    /// </param>
    public void Overlay(RoomControl roomControl, Room room, Config config)
    {
        if (config.Width != room.Width || config.Height != room.Height){
            throw new ConfigFormatException("Room and config dimensions do not match!");
        }

        for( int x = 0; x < room.Width; x++){
            for(int y = 0; y < room.Height; y++){

                // Only add the overlay if it's not already occupied by the room
                switch(room[x,y].Type){
                case TileType.BLANK:

                    var currentConf = config[x,y];
                    var currentPre = this[currentConf];

                    if (currentPre != null){

                        // Instantiate whatever the prefab is!
                        var o = GameObject.Instantiate(currentPre) as GameObject;

                        o.transform.position = CubeGen.Singleton.PositionFromIdx(roomControl.Position, new coords(x,y));

                        switch (currentConf){
                        case ObjectType.SNOW:
                            o.transform.localScale = new Vector3( CubeGen.Singleton.cubeSize, CubeGen.Singleton.cubeSize, CubeGen.Singleton.cubeSize);
                            var mRend = o.GetComponent(typeof(MeshRenderer)) as MeshRenderer;
                            mRend.material.color = new Color(1f,1f,1f);
                            o.tag = "SNOW";
                            o.layer = LayerMask.NameToLayer("Terrain");
                            roomControl.AddTerrain(o);
                            break;
                        case ObjectType.PLAYER_START:
                            roomControl.PlayerStart = o;
                            break;
                        case ObjectType.XLGRHTHBTRG:
                            var xc = o.GetComponent(typeof(XlGrhthbtrgControl)) as XlGrhthbtrgControl;
                            xc.player = player;
                            xc.currentState = EntityState.STILL;
                            xc.target = player.transform.Find("Armature/Hip");
                            o.layer = LayerMask.NameToLayer("Enemy");
                            roomControl.AddEnemy(xc);
                            break;
                        case ObjectType.WYRM:
                            numWyrms++;
                            var wc = o.GetComponent(typeof(WyrmControl)) as WyrmControl;
                            wc.player = player;
                            wc.currentState = EntityState.STILL;
                            o.layer = LayerMask.NameToLayer("Wyrm");
                            roomControl.AddEnemy(wc);
                            break;
                        case ObjectType.SHOGGOTH:
                            var sc = o.GetComponent(typeof(ShoggothControl)) as ShoggothControl;
                            sc.player = player;
                            sc.currentState = EntityState.STILL;
                            o.layer = LayerMask.NameToLayer("Enemy");
                            roomControl.AddEnemy(sc);
                            break;
                        }
                    }
                    break;
                default:
                    break;
                }
            }
        }
    }