//function for collision with a projectile
    void OnCollisionEnter(Collision coll)
    {
        GameObject otherColl = coll.gameObject;

        if (otherColl.tag == "ProjectileHero" || otherColl.tag == "homing")
        {
            Projectile p = otherColl.GetComponent <Projectile>();
            Destroy(otherColl);
            ChangeColour(false, 50, -75, -75, false); //changes colour to show the damage
            _colourChangeTime = Time.time;

            if (_bound.onScreen)
            {
                if (otherColl.tag == "homing")
                {
                    //missile collides many time with the enemy when it hits due to how it moves
                    //in order to deal with this it deals its damage during the next update (as this is after the spur of collisions)
                    //to the user this is not noticeable due to the speed of the frameRate
                    _healthDamageOnNextUpdate = Main_MainScene.GetWeaponDefinition(p.type).damage;
                }
                else
                {
                    _health -= Main_MainScene.GetWeaponDefinition(p.type).damage; //update health
                    CheckHealth();
                }
            }
        }
    }
    void Awake()
    {
        _weaponDictionary = new Dictionary <WeaponType, WeaponDefinition>(); //reset dictionary on awake
        _allEnemiesList   = new List <GameObject>();                         //reset list of enemies on awake
        if (scriptReference == null)
        {
            scriptReference = this; //sets up singleton so that only 1 main script can be created.
        }
        else
        {
            Debug.LogError("Attempted Creation of Second Main Script");
        }
        _boundM = GetComponent <BoundsCheck>();    //gets the bounds check component
        Invoke("SpawnEnemy", 1f / enemySpawnRate); //this start the enemies spawning

        //since this is a static reference it only needs to be set once when it is null and the data will remain - see PowerUp class for more detail
        if (PowerUp.allPossibleColors == null)
        {
            PowerUp.allPossibleColors = new List <Color>();
        }

        //adds the weapon definitions into the dictionary so they can be easily looked up later
        foreach (WeaponDefinition def in weaponDefn)
        {
            _weaponDictionary.Add(def.type, def);     //adds the definition for the weapons into the dictionary for easy look up later
            PowerUp.allPossibleColors.Add(def.color); //add colours to beused for random cube
        }
    }
示例#3
0
    //sets the powerup type depending on what WeaponDefinition / WeaponType is associated with it.
    public void SetType(WeaponType wt, bool isRandCube = false)
    {
        WeaponDefinition def = Main_MainScene.GetWeaponDefinition(wt);

        type     = wt;
        duration = def.duration;
        if (isRandCube)
        {
            _randCurrentColourIndex  = Random.Range(0, allPossibleColors.Count - 1);
            _cubeRend.material.color = allPossibleColors[_randCurrentColourIndex];
            letter.text = "?";
            _randCube   = true;
            Invoke("ColorChange", 0.1f); //invokes function to change color
        }
        else
        {
            _cubeRend.material.color = def.color;
            letter.text = def.letter;
        }
    }
示例#4
0
    public void SetType(WeaponType wt)
    {
        _type = wt;
        if (type == WeaponType.none)
        {
            this.gameObject.SetActive(false); //hides the gun if the weapon is none
        }
        else
        {
            this.gameObject.SetActive(true); //show gun if there is a weapon enabled
        }

        GameObject rootGo = transform.root.gameObject;

        if (rootGo.GetComponent <Hero_Script>() != null)
        {
            if (wt != WeaponType.plasmaThrower)
            {
                _plasmaThrowerParticles.enabled = false;                        //incase of switch while space is being held
                rootGo.GetComponent <Hero_Script>().FireWeaponsDelegate = Fire; //assigning fire the the function delegate
                rootGo.GetComponent <Hero_Script>().StopWeaponsFire     = null; //when not using plasma thrower no need to stop weapons fire
            }
            else
            {
                rootGo.GetComponent <Hero_Script>().FireWeaponsDelegate = FirePlasmaThrower; //different fire function for flame thrower
                rootGo.GetComponent <Hero_Script>().StopWeaponsFire     = StopPlasmaThrower; //there is a function to be triggered when space bar is lifted
            }
        }
        else if (rootGo.GetComponent <Enemy_3_Movement>() != null) //attach fire to enemy 3
        {
            rootGo.GetComponent <Enemy_3_Movement>().FireWeaponsDelegate = Fire;
        }
        else if (rootGo.GetComponent <Enemy_Boss_Movement>() != null) //attach multiple fire to boss
        {
            rootGo.GetComponent <Enemy_Boss_Movement>().FireWeaponsDelegate += Fire;
        }
        def          = Main_MainScene.GetWeaponDefinition(_type);
        lastShotTime = 0; //this means that weapon will be ready to fire right when it is switched to
    }
    protected virtual void Update()
    {
        Move(); //calls move which is defined in the child class

        //destroy enemy if its off screen
        if (_bound != null && (_bound.offScreenDown || _bound.offScreenLeft || _bound.offScreenRight))
        {
            Main_MainScene.scriptReference.DestroyEnemy(gameObject);
        }

        //deals damage if there is some to do on update
        if (_healthDamageOnNextUpdate != 0)
        {
            _health -= _healthDamageOnNextUpdate;
            _healthDamageOnNextUpdate = 0;
            CheckHealth();
        }

        //this hanldes what happens when the enemy is on fire
        if (_onFireTime != 0)
        {
            //determines if it is time to stop being on fire
            if ((Time.time - _onFireTime) > _timeToRemainOnFire)
            {
                ChangeColour(true); //resets colour
                _onFireTime = 0;
            }

            else
            {
                _health -= Main_MainScene.GetWeaponDefinition(WeaponType.plasmaThrower).damage *Time.deltaTime;  //damage the enemy while it is on fire,  damage is per second
                CheckHealth();

                //cycles the colour
                if ((Time.time - _onFireColourLastChageTime) > 0.1f)
                {
                    if (_higherColourFireCycleCounter)
                    {
                        ChangeColour(false, -15, 20, 20, true);
                    }
                    else
                    {
                        ChangeColour(false, 15, -20, -20, true);
                    }
                    _higherColourFireCycleCounter = !_higherColourFireCycleCounter;
                    _onFireColourLastChageTime    = Time.time;
                }
            }
        }

        //this handles what happens when the enemy is on frozen
        if (_frozenTime != 0)
        {
            //stop being frozen
            if ((Time.time - _frozenTime) > _timeToRemainFrozen)
            {
                _frozenTime  = 0;
                _speedFactor = 1f;
                ChangeColour(true);
            }
            else
            {
                _health -= Main_MainScene.GetWeaponDefinition(WeaponType.freezeGun).damage *Time.deltaTime;  //damage the enemy while it is on fire,  damage is per second
                CheckHealth();
            }
        }

        //resets colour after regular damage done
        if (_colourChangeTime != 0 && (Time.time - _colourChangeTime) > _timeToRemainColourChange && _onFireTime == 0 && _frozenTime == 0)
        {
            ChangeColour(true);
            _colourChangeTime = 0;
        }
    }