Beispiel #1
0
    public void disableUnit(GameObject unit)
    {
        if (unit)
        {
            inspector.setScriptsFrom(unit);
            //disable the navmesh agent component
            unit.GetComponent <NavMeshAgent>().enabled = false;
            unit.GetComponent <Collider>().enabled     = false;

            //if this is an archer, disable the archer functionality
            if (inspector.isScriptValid())
            {
                inspector.setEnable(false);
                //inspector.setSpread(levelData.spreadUnits);
            }
            if (unit.GetComponent <Archer>())
            {
                unit.GetComponent <Archer>().enabled = false;
            }

            /*
             * foreach (MonoBehaviour component in unit.GetComponents<MonoBehaviour>()) {
             *      if(component.type == "CustomBehaviour") {
             *              print("haha");
             *              this.enabled = false;
             *      }
             * }
             */
            //disable the health object
            unit.transform.Find("Health").gameObject.SetActive(false);

            //disable any particles
            foreach (ParticleSystem particles in unit.GetComponentsInChildren <ParticleSystem>())
            {
                particles.gameObject.SetActive(false);
            }

            //make sure it's playing an idle animation
            foreach (Animator animator in unit.GetComponentsInChildren <Animator>())
            {
                animator.SetBool("Start", false);
            }
        }
    }
Beispiel #2
0
    public override void RewardAtEpisodeEnds(UnitInspect inspector, GameSystem sys)
    {
        float AllDamaged = (inspector.getCurrentEnemys().Length <= 0)?0:inspector.AvgLives(inspector.getCurrentEnemys());

        //Rewarding globally
        foreach (GameObject knight in inspector.getInstantiatedKnights())
        {
            inspector.setScriptsFrom(knight);
            if (inspector.isScriptValid() && inspector.getScriptType() == "AgentScript")
            {
                BagReset();
                AddReward((1 - ((AllDamaged) / sys.AllInitLives)) * 2f);
                Apply(inspector.AgentScript);
            }
        }

        /*
         * //Rewarding reamined units
         * foreach(GameObject knight in inspector.getCurrentKnights()) {
         *  inspector.AgentAddRewardDircetly(1f);
         * }
         */
    }
Beispiel #3
0
    void FixedUpdate()
    {
        if (lives != lastLives && Academy.showeffects)
        {
            if (!DamagedParticle.isPlaying)
            {
                DamagedParticle.Play();
                //DamagedParticle.Simulate(Time.unscaledDeltaTime, true, false);
            }
            lastLives = lives;
        }

        //find closest enemy
        //ML:relating to moves
        if (currentTarget != null)
        {
            inspector.setScriptsFrom(currentTarget.gameObject);
            if (!inspector.isScriptValid() || inspector.isDead())
            {
                currentTarget = findCurrentTarget();
            }
        }
        else
        {
            currentTarget = findCurrentTarget();
        }


        //if character ran out of lives, it should die
        if (lives < 0 && !dead)
        {
            die();
        }
        else
        {
            if (Vector3.Distance(agent.destination, transform.position) <= agent.stoppingDistance && currentTarget != null)
            {
                int sign  = rnd.Next(0, 2) * 2 - 1;
                int sign2 = rnd.Next(0, 2) * 2 - 1;
                agent.destination = new Vector3(currentTarget.position.x + (float)gausianRand() * RandomRange * sign, currentTarget.position.y, currentTarget.position.z + (float)gausianRand() * RandomRange * sign2);
                agent.isStopped   = false;
            }
            else if (currentTarget == null)
            {
                agent.destination = getRandomPosition(area);
            }
            if (isPassedCooltime)              //&& (rnd.Next(0, 2) * 2 - 1)>0) {
            {
                foreach (GameObject unit in HitboxComponent.GetCollideObjects())
                {
                    if (unit == null && !ReferenceEquals(unit, null))
                    {
                        HitboxComponent.RemoveObject(unit);
                        continue;
                    }
                    if (unit.CompareTag("Knight"))
                    {
                        if (inspector.setScriptsFrom(unit) && !inspector.isDead())
                        {
                            inspector.setLives(inspector.getLives() - (damage));
                            if (inspector.getLives() < 0)
                            {
                                HitboxComponent.RemoveObject(unit);
                            }
                        }
                        else
                        {
                            Debug.LogWarning("Invalid Target Triggered.");
                        }
                    }
                }
                isPassedCooltime = false;
                StartCoroutine("Cooltime");
            }
        }
        //ML:relating to moves
    }