public void FireLasers()
    {
        TurnToFace();
        float angle         = Vector2Extentions.GetAngle((PlayerCharacter.GetPostion() - laserSpawnPosition.position).normalized);
        int   lasersToShoot = numLasers + phase * 4;

        for (int i = 0; i < lasersToShoot; i++)
        {
            float percent = (float)i / lasersToShoot;
            percent = -1f + 2f * percent;
            float angleOffset = (percent * (lasersToShoot / 6f)) + Random.Range(-0.1f, 0.1f);
            if (i == lasersToShoot / 2)
            {
                angleOffset = 0;
            }
            quaternion rot          = quaternion.Euler(0, 0, angle + angleOffset);
            float      fireWaitTime = ((float)i / lasersToShoot) * (laserFireTime + lasersToShoot * 0.05f);

            StartCoroutine(FireSingleLaser(rot, fireWaitTime));
        }

        var pos = PlayerCharacter.GetPostion();

        if (pos.y > heightBarrier)
        {
            for (int i = 0; i < 5; i++)
            {
                StartCoroutine(FireTopLasers(new Vector3(0, -i, 0), i * 0.15f));
            }
        }
    }
示例#2
0
    void Update()
    {
        lineRenderer.SetPosition(0, (Vector2)transform.position);
        if (!locked)
        {
            target = PlayerCharacter.GetPostion();
            if (!direct)
            {
                target = target + PlayerCharacter.GetVelocity() * leadTime;
            }
        }
        else
        {
            target = transform.position + transform.right;
        }

        if (Vector2.Distance(target, transform.position) < lockDistance)
        {
            locked = true;
            lineRenderer.enabled = false;
        }

        lineRenderer.SetPosition(1, target);

        float angle = Vector2Extentions.GetAngle((target - (Vector2)transform.position).normalized);

        if (locked)
        {
            rotationSpeed += Time.deltaTime * 50;
        }

        transform.rotation  = Quaternion.RotateTowards(transform.rotation, quaternion.Euler(0, 0, angle), Time.deltaTime * rotationSpeed);
        transform.position += Time.deltaTime * speed * transform.right;
    }
    public void BeginShootSpikes()
    {
        TurnToFace();
        float angle     = Vector2Extentions.GetAngle((PlayerCharacter.GetPostion() - laserSpawnPosition.position).normalized);
        int   numSpikes = 6 + phase * 2;
        bool  direct    = Random.Range(0, 2) == 0;

        for (int i = 0; i < numSpikes; i++)
        {
            float percent = (float)i / numSpikes;
            percent = -1f + 2f * percent;
            float angleOffset = (percent * (numSpikes / 6f)) + Random.Range(-0.1f, 0.1f);
            if (i == numSpikes / 2)
            {
                angleOffset = 0;
            }
            quaternion rot          = quaternion.Euler(0, 0, angle + angleOffset);
            float      fireWaitTime = ((float)i / numSpikes) * (laserFireTime + numSpikes * 0.05f);

            StartCoroutine(FireSingleSpike(rot, fireWaitTime, direct));
        }
    }
    void Update()
    {
        var hit = Physics2D.Raycast(transform.position, initialDirection, float.PositiveInfinity, wallLayers);

        if (hit.collider != null)
        {
            lineRenderer.SetPosition(1, hit.point);
        }

        float   eval     = laserCurve.Evaluate(time);
        Vector3 otherPos = lineRenderer.GetPosition(1);
        Vector2 dif      = otherPos - transform.position;
        var     angle    = Vector2Extentions.GetAngle(dif);

        transform.rotation = quaternion.Euler(0, 0, angle);

        if (eval > 0.7 && !didHurt)
        {
            didHurt = true;
            var go = Instantiate(hurtPrefab, transform.position, quaternion.Euler(0, 0, angle));
            //TODO: add damage to hurt prefab
            go.transform.localScale = new Vector3(dif.magnitude, 1, 1);
            Destroy(go, 0.1f);
        }
        else
        {
            lineRenderer.SetPosition(0, (Vector2)transform.position);
        }


        var width = eval * laserWidth;

        lineRenderer.widthMultiplier = width;
        if (time > 1f)
        {
            Destroy(gameObject);
        }
        time += Time.deltaTime * animationSpeed;
    }