Example #1
0
    // Update is called once per frame
    void Update()
    {
        attackCounter -= Time.deltaTime;

        if (attackCounter < 0)
        {
            attackCounter = 0;
        }

        if (attackCounter == 0 && target && Vector3.Distance(transform.position, target.transform.position) <= attackRange)
        {
            HealthScript health = target.GetComponent <HealthScript>();

            if (health)
            {
                health.Hurt(strength);
                attackCounter = attackInterval;
            }

            FlameScript flameScript = target.GetComponent <FlameScript>();

            if (flameScript)
            {
                flameScript.power -= strength;

                if (flameScript.power < 0)
                {
                    flameScript.power = 0;
                }

                Destroy(gameObject);
            }
        }
    }
Example #2
0
    void Awake()
    {
        instance = this;

        foreach (GameObject g in dontDestroy)
        {
            DontDestroyOnLoad(g);
        }
    }
Example #3
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="collision"></param>
    private void OnTriggerExit2D(Collider2D collider)
    {
        FlameScript flame = collider.gameObject.GetComponent <FlameScript>();

        if (flame != null)
        {
            //windSound.velocityUpdateMode = AudioVelocityUpdateMode.
            windSound.volume = 0.3f;
        }
    }
Example #4
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="collision"></param>
    private void OnTriggerEnter2D(Collider2D collider)
    {
        //indicatorUI.GetComponent<UnityEngine.UI.Image>().color = new Color(0, 0, 0, 0);
        FlameScript flame = collider.gameObject.GetComponent <FlameScript>();

        if (flame != null)
        {
            windSound.volume = 1f;
        }
    }
Example #5
0
    public void Init(int force, Vector3 direction, bool stop)
    {
        this.transform.localPosition += direction;
        if (!stop && force > 0)
        {
            RaycastHit2D hit       = Physics2D.Raycast(this.transform.localPosition + direction, Vector2.zero);
            bool         breakable = true;
            if (hit.collider != null)
            {
                WallScript ws;
                if (ws = hit.collider.gameObject.GetComponent <WallScript>())
                {
                    stop      = true;
                    breakable = ws.breakable;
                    ws.DestroyWall();
                }
            }
            if (breakable)
            {
                GameObject flame = Instantiate(this.gameObject);
                flame.transform.localPosition = this.transform.localPosition;
                FlameScript fs = flame.GetComponent <FlameScript>();
                fs.Init(force - 1, direction, stop);
            }


            //Create a Light
            lightGameObject = new GameObject("Flame Light");

            //Set Light properties:
            Light lightComp = lightGameObject.AddComponent <Light>();
            lightComp.color     = Color.white;
            lightComp.range     = 3;
            lightComp.intensity = 7;

            //Set the position of the light:
            Vector3 lightPosition = this.transform.localPosition;
            lightPosition.z = -1;
            lightGameObject.transform.position = lightPosition;
        }
    }
Example #6
0
    private void CreateFlame(Vector3 position, Vector3 direction)
    {
        RaycastHit2D hit = Physics2D.Raycast(position + direction, Vector2.zero);

        bool breakable = true, stop = false;

        if (hit.collider != null)
        {
            WallScript ws;
            if (ws = hit.collider.gameObject.GetComponent <WallScript>())
            {
                stop      = true;
                breakable = ws.breakable;
                ws.DestroyWall();
            }
        }
        if (breakable)
        {
            GameObject flame = Instantiate(this.FlamePrefab);
            flame.transform.localPosition = this.transform.localPosition;
            FlameScript fs = flame.GetComponent <FlameScript>();
            fs.Init(this.Force - 1, direction, stop);
        }
    }
Example #7
0
    /// <summary>
    /// When a bomb explode
    /// </summary>
    public void Explode()
    {
        //Play bomb explosion sound:
        SoundManager.instance.RandomizeSfx(sound_bomb_explosion);

        StopCoroutine(TimeBomb());
        //int dir = 1;
        GameObject flame = Instantiate(this.FlamePrefab);

        flame.transform.localPosition = this.transform.localPosition;
        FlameScript fs = flame.GetComponent <FlameScript>();

        fs.Init(0, Vector3.zero, false);

        CreateFlame(this.transform.localPosition, Vector3.left);
        CreateFlame(this.transform.localPosition, Vector3.right);
        CreateFlame(this.transform.localPosition, Vector3.up);
        CreateFlame(this.transform.localPosition, Vector3.down);

        Destroy(this.gameObject);

        //Remove the bomb location from the map used by IAIntelligence:
        IAIntelligence.INSTANCE.removeEntityFromMap(Mathf.Round(this.transform.localPosition.x), Mathf.Round(this.transform.localPosition.y), "BOMB");
    }
Example #8
0
    /// <summary>
    ///
    /// </summary>
    private void FixedUpdate()
    {
        // Vector2 movement = Vector2.zero;
        // movement.x = inputX * speed;
        // movement.y = inputY * speed;

        // transform.Translate(movement);

        if (!canInteract)
        {
            return;
        }

        Vector2 direction = new Vector2(
            inputX,
            inputY
            ).normalized;

        if (direction != Vector2.zero)
        {
            transform.Find("Flame").GetComponent <Animator>().SetBool("isMoving", true);
        }
        else
        {
            transform.Find("Flame").GetComponent <Animator>().SetBool("isMoving", false);
        }

        if (lastDirection != direction && lastDirection == Vector2.zero)
        {
            GroupUnitScript[] units = GameObject.FindObjectsOfType <GroupUnitScript>();

            foreach (GroupUnitScript unit in units)
            {
                if (!unit.isEnrolled)
                {
                    continue;
                }

                unit.waitMove = Random.Range(0.05f, 0.55f);
            }
        }

        // GameObject.FindGameObjectWithTag("Flamme").transform.Translate(direction * speed);
        // GameObject.FindGameObjectWithTag("Group").transform.Find("Group Positions").position = Vector2.Lerp(transform.position, GameObject.FindGameObjectWithTag("Flamme").transform.position, 1f);

        FlameScript flameScript = GameObject.FindGameObjectWithTag("Flamme").GetComponent <FlameScript>();

        Rigidbody2D flameBody   = GameObject.FindGameObjectWithTag("Flamme").GetComponent <Rigidbody2D>();
        Vector2     newVelocity = direction * speed;

        if (flameScript.wind)
        {
            newVelocity.x /= 3f;
            newVelocity   += flameScript.wind.speed * 5f;
        }

        flameBody.velocity = newVelocity;

        //GameObject.FindGameObjectWithTag("Flamme").transform.Translate(direction * speed);
        GameObject.FindGameObjectWithTag("Group").transform.Find("Group Positions").position = Vector2.Lerp(transform.position, GameObject.FindGameObjectWithTag("Flamme").transform.position, 1f);

        /*
         * // Move flame protection collider
         * ZoneProtectFlameScript[] zoneProtectFlameScript = GameObject.FindGameObjectWithTag("Flamme").GetComponentsInChildren<ZoneProtectFlameScript>();
         * for(int i = 0; i < zoneProtectFlameScript.Length; i++)
         * {
         *  zoneProtectFlameScript[i].transform.position = new Vector3(flameBody.position.x, flameBody.position.y, 0);
         *  //zoneProtectFlameScript[i].transform.position = GameObject.FindGameObjectWithTag("Flamme").transform.position;
         *  //zoneProtectFlameScript[i].GetComponent<Rigidbody2D>().velocity = direction * speed;
         *
         *  //zoneProtectFlameScript[i].transform.position = new Vector3(0, 0, 0);
         * }
         */

        lastDirection = direction;
    }