示例#1
0
    // Update is called once per frame
    public void Update()
    {
        health = (int)parentScript.stats["health"].getCompoundValue();
        armor  = (int)parentScript.stats["armor"].getCompoundValue();
        FloatStat MD = parentScript.stats["damage"];

        MD.removeFactor("isDangerous");
        meleeDamage = (int)MD.getCompoundValue();
        myAi        = parent.GetComponent <AiScriptBase>();
        MD.setFactor("isDangerous", myAi.isDangerous() ? 1 : 0);
        //if (start) Start();
        //parent.GetComponent<Rigidbody2D>().GetVector();
        direction = direction.normalized;
    }
示例#2
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        GameObject   other   = collision.gameObject;
        EntityScript otherES = other.GetComponent <EntityScript>();

        //Debug.Log(gameObject + "-->" + other);
        if (gameObject.CompareTag(GameDefaults.Projectile()) && (other.CompareTag(GameDefaults.Obstruction())))
        {
            Destroy(gameObject);
            return;
        }
        if (gameObject.CompareTag(GameDefaults.Projectile()) && other.CompareTag(GameDefaults.Projectile()))
        {
            return;
        }
        if (gameObject.CompareTag(GameDefaults.Powerup()) && !other.CompareTag(GameDefaults.Player()))
        {
            return;
        }
        if (other.CompareTag(GameDefaults.Powerup()))
        {
            return;
        }
        if (other.CompareTag(GameDefaults.Obstruction()))
        {
            return;
        }

        if (otherES != null)
        {
            if (parent != null)
            {
                if (other.gameObject.CompareTag(parent.tag) || otherES.parent != null && otherES.parent.gameObject.CompareTag(gameObject.tag))
                {
                    return;
                }
            }

            foreach (string effect in impactEffects.Keys)
            {
                //Debug.Log(effect);
                if (effect.Equals("damage"))
                {
                    if (gameObject.CompareTag(GameDefaults.Enemy()))
                    {
                        if (!gameObject.GetComponent <AiScriptBase>().isDangerous())
                        {
                            continue;
                        }
                        else
                        {
                            gameObject.GetComponent <AiScriptBase>().setDanger(false);
                        }
                    }
                    if (!otherES.stats.ContainsKey("health"))
                    {
                        continue;
                    }

                    float x = impactEffects["damage"].value;
                    if (otherES.stats.ContainsKey("armor"))
                    {
                        FloatStat FSA = otherES.stats["armor"];
                        if (FSA.getCompoundValue() >= 100)
                        {
                            x = 0;
                        }
                        else
                        {
                            x = Mathf.Max(x - FSA.getCompoundValue(), 1f);
                        }
                    }
                    FloatStat FSH = otherES.stats["health"];
                    otherES.controller.damage((int)x);
                    FSH.ChangeWithFactor("baseValue", 0 - x);
                    FSH = new FloatStat("health", Mathf.RoundToInt(FSH.getCompoundValue()));
                }
                else if (effect.Equals("healthBoost"))
                {
                    if (!otherES.stats.ContainsKey("health"))
                    {
                        continue;
                    }

                    float     x   = impactEffects["health"].value;
                    FloatStat FSH = otherES.stats["health"];

                    FSH.ChangeWithFactor("baseValue", x);
                }
                else
                {
                    FSQI effectData = impactEffects[effect];
                    Debug.Log(otherES.stats.ContainsKey(effect).ToString() + effect);
                    if (!otherES.stats.ContainsKey(effect))
                    {
                        continue;
                    }
                    effectData.ApplyTo(otherES);
                }
            }
        }
        if (gameObject.CompareTag(GameDefaults.Powerup()) && other.CompareTag(GameDefaults.Player()))
        {
            Destroy(gameObject);
            return;
        }
        //Stari kod
        if (true) //Unity ima ugrađene tagove i layere, zasto si stvarao svoje?
        {
            //Projectile collisions
            if (gameObject.CompareTag(GameDefaults.Projectile()))
            {
                //Obstruction
                if (other.CompareTag(GameDefaults.Obstruction()))
                {
                    Destroy(gameObject);
                    return;
                }
                if (parent != null && !parent.CompareTag(other.gameObject.tag))
                {
                    controller.OnTriggerEnter2D(collision);
                    GameObject.Destroy(gameObject);

                    // Wake up any script that is attached to the enemy + navmesh
                    var otherChaser = other.GetComponent <AiScriptBase>();
                    if (otherChaser != null && !otherChaser.enabled)
                    {
                        otherChaser.enabled = true;
                        other.GetComponent <NavMeshAgent>().enabled = true;
                    }
                }
            }
            //Enemy coll
            else if (gameObject.CompareTag(GameDefaults.Enemy()))
            {
                //Obstruction
                if (other.CompareTag(GameDefaults.Obstruction()))
                {
                    //Zid
                }
                //Enemy
                else if (other.CompareTag(GameDefaults.Enemy()))
                {
                    //var es = other.gameObject.GetComponent<EntityScript>();
                }
                //Player
                else if (other.gameObject.CompareTag(GameDefaults.Player()))
                {
                    if (controller != null && collision != null)
                    {
                        controller.OnTriggerEnter2D(collision);
                    }
                }
            }
            else if (gameObject.CompareTag(GameDefaults.Player()))
            {
                if (other.gameObject.CompareTag(GameDefaults.LevelExit()))
                {
                    if (controller != null && collision != null)
                    {
                        controller.OnTriggerEnter2D(collision);
                    }
                }
            }
        }
    }