Exemplo n.º 1
0
    private void OnTriggerEnter(Collider other)
    {
        var unit = other.GetComponent <Unit>();

        if (unit)
        {
            if (unit.isAlive && unit != caster)
            {
                var effect = Instantiate(hitEffect,
                                         unit.GetUnitPoint(UnitBodyPoints.chest).position, transform.rotation);

                var audioSource = effect.GetComponent <AudioSource>();
                if (audioSource && hitSound != null && !unit.isDefending)
                {
                    audioSource.PlayOneShot(hitSound);
                }

                if (!unit.isDefending)
                {
                    if (canStick)
                    {
                        StickTo(unit);
                    }
                }
                else
                {
                    if (canStick && !canBreak)
                    {
                        StickTo(unit);
                    }
                    if (!canStick && canBreak)
                    {
                        BreakOff(unit);
                    }
                    if (canStick && canBreak)
                    {
                        if (!RandomExtensions.Bool(breakChance))
                        {
                            StickTo(unit);
                        }
                        else
                        {
                            BreakOff(unit);
                        }
                    }
                }


                unit.TakeDamage(damage, caster);

                Destroy(gameObject);
            }
        }
    }
Exemplo n.º 2
0
    void DeployAsteroid(Vector3 posMin, Vector3 posMax, int level, float offset)
    {
        var asteroid = GetAsteroid(level);

        if (asteroid == null)
        {
            return;
        }

        var deployOnSides = RandomExtensions.Bool();
        var deployOnLeft  = RandomExtensions.Bool();

        var ax1Min = deployOnSides ? posMin.x : posMin.y;
        var ax1Max = deployOnSides ? posMax.x : posMax.y;
        var ax2Min = deployOnSides ? posMin.y : posMin.x;
        var ax2Max = deployOnSides ? posMax.y : posMax.x;

        var ax1     = deployOnLeft ? ax1Min - offset : ax1Max + offset;
        var quarter = (ax2Max - ax2Min) / 4f;
        var ax2     = ax2Min + quarter + quarter * 2f * Random.value;

        var position = new Vector3(deployOnSides ? ax1 : ax2, deployOnSides ? ax2 : ax1, 0);

        Vector3 direction;

        if (deployOnSides)
        {
            direction = deployOnLeft ? Vector3.right : Vector3.left;
        }
        else
        {
            direction = deployOnLeft ? Vector3.up : Vector3.down;
        }

        asteroid.transform.position = position;
        asteroid.transform.rotation = Quaternion.FromToRotation(Vector3.up, direction);
        asteroid.transform.Rotate(0, 0, Random.Range(-DirectionOffset, DirectionOffset));
        asteroid.SetActive(true);

        _asteroidCount += 1;
    }
Exemplo n.º 3
0
    void DeployEnemy(GameObject enemy, Vector3 posMin, Vector3 posMax, float offset)
    {
        if (enemy == null)
        {
            return;
        }

        var deployOnSides = RandomExtensions.Bool();
        var deployOnLeft  = RandomExtensions.Bool();

        var ax1Min = deployOnSides ? posMin.x : posMin.y;
        var ax1Max = deployOnSides ? posMax.x : posMax.y;
        var ax2Min = deployOnSides ? posMin.y : posMin.x;
        var ax2Max = deployOnSides ? posMax.y : posMax.x;

        var ax1     = deployOnLeft ? ax1Min - offset : ax1Max + offset;
        var quarter = (ax2Max - ax2Min) / 4f;
        var ax2     = ax2Min + quarter + quarter * 2f * Random.value;

        var position = new Vector3(deployOnSides ? ax1 : ax2, deployOnSides ? ax2 : ax1, 0);

        enemy.transform.position = position;
        enemy.SetActive(true);
    }