Ejemplo n.º 1
0
    void DrawBezier()
    {
        float   length  = 0f;
        Vector3 lastPos = p0.position;

        while (length < 1)
        {
            Vector3   Apos      = Vector3.Lerp(p0.position, p1.position, length);
            Vector3   Bpos      = Vector3.Lerp(p1.position, p2.position, length);
            Vector3   tempPos   = Vector3.Lerp(Apos, Bpos, length);
            Vector3[] controles = new Vector3[] { p0.position, p1.position, p2.position };
            Vector3   final_pos = getBezierPos(controles, length);

            GLDebug.DrawLine(lastPos, final_pos, Color.red, 0, true);

            if (showNormals)
            {
                DrawNormal(Apos, Bpos, tempPos);
            }


            lastPos = tempPos;
            length += precision;
        }
        GLDebug.DrawLine(lastPos, p2.position, Color.red, 0, true);
    }
Ejemplo n.º 2
0
    IEnumerator Thorn()
    {
        while (true)
        {
            GameObject gun = GameObject.FindWithTag("MyGun");
            transform.position = gun.transform.rotation * Vector3.up * currDist + gun.transform.position;
            transform.rotation = gun.transform.rotation;
            GLDebug.DrawLine(transform.position, gun.transform.position + transform.rotation * (new Vector3(0, 0.05f, 0)), Color.black);
            GLDebug.DrawLine(transform.position + (transform.rotation * Vector3.right * 0.015f), gun.transform.position + transform.rotation * (new Vector3(0, 0.05f, 0)) + (transform.rotation * Vector3.right * 0.015f), Color.black);
            GLDebug.DrawLine(transform.position - (transform.rotation * Vector3.right * 0.015f), gun.transform.position + transform.rotation * (new Vector3(0, 0.05f, 0)) - (transform.rotation * Vector3.right * 0.015f), Color.black);

            if (currDist < range && dir)
            {
                currDist += Time.deltaTime * speed;
            }
            else
            {
                dir       = false;
                currDist -= Time.deltaTime * speed * 5;
                if (currDist <= 0.1f)
                {
                    Destroy(this.gameObject);
                    gun.GetComponent <GunScript>().isntCD = true;
                }
            }
            yield return(0);
        }
    }
Ejemplo n.º 3
0
    private void CreateCutPlane()
    {
        Vector3 center = Vector3.Lerp(_startPos, _endPos, .5f);
        Vector3 cut    = (_endPos - _startPos).normalized;
        Vector3 fwd    = (center - cylinder.transform.position).normalized;
        Vector3 normal = Vector3.Cross(fwd, cut).normalized;


        GLDebug.DrawLine(center, center + normal, Color.red, 2f, false);
        GLDebug.DrawLine(center + fwd * CutPlaneSize / 2f + cut * CutPlaneSize / 2f, center + fwd * CutPlaneSize / 2f + cut * CutPlaneSize / -2f, Color.green, 2f);
        GLDebug.DrawLine(center + fwd * CutPlaneSize / 2f + cut * CutPlaneSize / -2f, center + fwd * CutPlaneSize / -2f + cut * CutPlaneSize / -2f, Color.green, 2f);
        GLDebug.DrawLine(center + fwd * CutPlaneSize / -2f + cut * CutPlaneSize / -2f, center + fwd * CutPlaneSize / -2f + cut * CutPlaneSize / 2f, Color.green, 2f);
        GLDebug.DrawLine(center + fwd * CutPlaneSize / -2f + cut * CutPlaneSize / 2f, center + fwd * CutPlaneSize / 2f + cut * CutPlaneSize / 2f, Color.green, 2f);



        goCutPlane = Instantiate(CutPlane);

        goCutPlane.transform.position = center;
        goCutPlane.transform.up       = normal;

        offset = pointer.transform.position - goCutPlane.transform.position;

        pointerrotation = pointer.transform.rotation;
        objectrotation  = goCutPlane.transform.rotation;
    }
Ejemplo n.º 4
0
 public override void drawDebug()
 {
     if (Util.isAlive(this.target))
     {
         Color c = this.unit.attack.inRangeToAttack(this.target) ? Color.green : Color.red;
         GLDebug.DrawLine(this.unit.getPos(), this.target.getPos(), c);
     }
 }
Ejemplo n.º 5
0
 protected virtual void Update()
 {
     if (WeaponsSettings.drawLineFromGun)
     {
         Vector3 start, end;
         this.GetLineFromGun(out start, out end);
         GLDebug.DrawLine(start, end, Color.red, 0, true);
     }
 }
Ejemplo n.º 6
0
    internal void shot(GameObject obj)
    {
        //Debug.DrawLine(lineOfSight.transform.position, obj.transform.position, Color.green);
        GLDebug.DrawLine(lineOfSight.transform.position, obj.transform.position, Color.green);

        if (!audioSrc.isPlaying)
        {
            audioSrc.Play();
            StartCoroutine(restoreAudio());
        }
    }
Ejemplo n.º 7
0
    public override void drawDebug()
    {
        base.drawDebug();

        // Draw lines to the target and drop off point.
        bool flag = this.unit.canHoldMore();

        if (Util.isAlive(this.target))
        {
            GLDebug.DrawLine(this.unit.getPos(), this.target.getPos() + Vector3.up, this.closeEnough() ? Colors.green : Colors.red);
        }
    }
Ejemplo n.º 8
0
        public override void drawDebug()
        {
            foreach (Vector3 v in this.points)
            {
                GLDebug.DrawArrow(v, Vector3.up * 2.5f, 0.25f, 20, v == this.whackPoint ? Colors.orange : Color.yellow);
            }

            if (Util.isAlive(this.building))
            {
                GLDebug.DrawLine(this.unit.getPos(), this.building.getPos(), this.func() ? Colors.green : Colors.red);
            }
        }
Ejemplo n.º 9
0
    public override void drawDebug()
    {
        base.drawDebug();

        // Draw a line to mark the point and a line to conenct the unit to it's point.
        GLDebug.DrawLine(pointToDefend, pointToDefend + Vector3.up * 4, Color.black);
        GLDebug.DrawLine(unit.getPos(), pointToDefend, Color.gray);
        foreach (Direction d in Direction.horizontal)
        {
            GLDebug.DrawLine(pointToDefend, pointToDefend + (d.vector * Constants.AI_FIGHTING_DEFEND_RANGE), Color.black);
        }
    }
Ejemplo n.º 10
0
        public override void drawDebug()
        {
            base.drawDebug();

            // Draw a line to mark the point and a line to conenct the unit to it's point.
            GLDebug.DrawLine(this.defendPoint, this.defendPoint + Vector3.up * 4, Color.black);
            GLDebug.DrawLine(this.unit.getPos(), this.defendPoint, Color.gray);
            foreach (Vector3 v in Direction.CARDINAL)
            {
                GLDebug.DrawLine(this.defendPoint, this.defendPoint + (v * Constants.AI_FIGHTING_DEFEND_RANGE), Color.black);
            }
        }
Ejemplo n.º 11
0
    public override void drawDebug()
    {
        foreach (Vector3 point in this.points)
        {
            Color color = point == this.whackPoint ? Colors.orange : Color.yellow;
            GLDebug.DrawArrow(point, Vector3.up * 2.5f, 0.25f, 20, color);
        }

        if (Util.isAlive(this.building))
        {
            GLDebug.DrawLine(this.unit.getFootPos(), this.building.getPos(), this.isNextToWhackPoint() ? Colors.green : Colors.red);
        }
    }
Ejemplo n.º 12
0
    void Update()
    {
        pA.position     = Vector3.Lerp(p0.position, p1.position, t);
        pB.position     = Vector3.Lerp(p1.position, p2.position, t);
        target.position = Vector3.Lerp(pA.position, pB.position, t);


        GLDebug.DrawLine(pA.position, pB.position, Color.grey, 0, true);
        GLDebug.DrawLine(p0.position, p1.position, Color.grey, 0, true);
        GLDebug.DrawLine(p1.position, p2.position, Color.grey, 0, true);
        if (showCurve)
        {
            DrawBezier();
        }
    }
Ejemplo n.º 13
0
    void Update()
    {
        if (Input.GetKeyDown("r"))
        {
            Application.LoadLevel(Application.loadedLevel);
        }

        // MOUSE : Power Adjust
        if (Input.GetAxis("Mouse ScrollWheel") != 0)
        {
            dist += Input.GetAxis("Mouse ScrollWheel");
            //if (dist>minDist) dist=minDist;
            dist = Mathf.Clamp(dist, maxDist, minDist);
            //Debug.Log("dist:"+dist);
            slider.value = -maxDist - minDist - (dist + -maxDist - minDist);
            //slider.image.color = Color.Lerp(Color.green,Color.red,slider.normalizedValue);
            //Debug.Log(slider.normalizedValue);
        }

        // MOUSE: Get mouse position
        Vector3 mPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10));

        // rotate stick around ball
        if (follow)
        {
            // TODO: add force distance here?
            Vector3 temp = (stick.position - ball.position).normalized;
            stick.rotation       = Quaternion.LookRotation(Vector3.forward, mPos - ball.position);
            stick.position       = ball.position;
            stick.localPosition += stick.up * dist;

            // raycast from ball to forward
            hit = Physics2D.CircleCast(ball.position, ballRadius, stick.up, 99, layerMaskBallsAndWalls);

            // we hit other balls
            if (hit.collider != null)
            {
                // from stick/ball to target
                GLDebug.DrawLine(stick.position, hit.centroid, Color.white, 0, false);

                // circle preview gizmo
                GLDebug.DrawCircle(hit.centroid, ballRadius, Color.yellow, 0, false);

                // get reflection direction for whiteball
                Vector3 reflectDir = Vector3.Reflect((new Vector3(hit.centroid.x, hit.centroid.y, 0) - stick.position).normalized, hit.normal);

                GLDebug.DrawRay(hit.centroid, reflectDir, Color.yellow, 0, false);

                // target ball estimated direction
                if (hit.collider.CompareTag("Ball"))
                {
                    Vector3 targetDir = (hit.transform.position - new Vector3(hit.centroid.x, hit.centroid.y, 0)).normalized * 10;
                    GLDebug.DrawRay(hit.centroid, targetDir, Color.red, 0, false);
                }
            }
            else
            { // no hit on balls
              // then raycast to walls instead
                hit = Physics2D.CircleCast(stick.position, ballRadius, stick.up, 99, layerMaskWalls);
                if (hit.collider != null)
                {
                    GLDebug.DrawLine(stick.position, hit.centroid, Color.red, 0, false);
                    Vector3 reflectDir2 = Vector3.Reflect((new Vector3(hit.centroid.x, hit.centroid.y, 0) - stick.position).normalized, hit.normal);
                    GLDebug.DrawRay(hit.centroid, reflectDir2, Color.red, 0, false);
                }
                else
                {
                }
            }
        }

        // MOUSE: Shoot
        if (follow && Input.GetMouseButtonUp(0)) // && hit.collider != null)
        {
            stick.GetComponent <AudioSource>().volume = Mathf.Lerp(0, 1, ReMap(dist, maxDist, minDist, 1, 0));
            stick.GetComponent <AudioSource>().Play();
            Vector3 forceDir = (ball.position - stick.position).normalized * -(dist - minDist - 0.02f) * forceMultiplier;
            ball.GetComponent <Rigidbody2D>().AddForce(forceDir, ForceMode2D.Impulse);
            follow = false;
            Invoke("HideShowStick", 0.2f);
        }

        // start following
        if (!follow)
        {
            if (ball.GetComponent <Rigidbody2D>().velocity.sqrMagnitude < 0.015f)
            {
                follow = true;
                selectionFx.GetComponent <Fader>().StartFade();
                Invoke("HideShowStick", 0.2f);
            }
        }
    } // update()
 public IEnumerator fourLasers()
 {
     while (true)
     {
         RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, Vector2.up, 100);
         for (int i = 1; i < hits.Length; i++)
         {
             if (!hits[i].collider.isTrigger)
             {
                 hit = hits[i];
                 if (hit.collider.gameObject.tag == "cell")
                 {
                     hit.collider.gameObject.GetComponent <CellMover>().health -= 2.5f;
                 }
                 break;
             }
         }
         if (hit.collider != null && !hit.collider.isTrigger)
         {
             for (int c = 0; c < 10; c++)
             {
                 GLDebug.DrawLine(transform.position + new Vector3(0, 1, 0) + (Vector3.right * 0.015f * c),
                                  hit.point + new Vector2((Vector2.right * 0.015f * c).x, (Vector2.right * 0.015f * c).y), Color.magenta);
                 GLDebug.DrawLine(transform.position + new Vector3(0, 1, 0) - (Vector3.right * 0.015f * c),
                                  hit.point - new Vector2((Vector2.right * 0.015f * c).x, (Vector2.right * 0.015f * c).y), Color.magenta);
             }
         }
         hits = Physics2D.RaycastAll(transform.position, -Vector2.up, 100);
         for (int i = 1; i < hits.Length; i++)
         {
             if (!hits[i].collider.isTrigger)
             {
                 hit = hits[i];
                 if (hit.collider.gameObject.tag == "cell")
                 {
                     hit.collider.gameObject.GetComponent <CellMover>().health -= 2.5f;
                 }
                 break;
             }
         }
         if (hit.collider != null && !hit.collider.isTrigger)
         {
             for (int c = 0; c < 10; c++)
             {
                 GLDebug.DrawLine(transform.position + new Vector3(0, -1, 0) + (-Vector3.right * 0.015f * c),
                                  hit.point + new Vector2((-Vector2.right * 0.015f * c).x, (-Vector2.right * 0.015f * c).y), Color.magenta);
                 GLDebug.DrawLine(transform.position + new Vector3(0, -1, 0) - (-Vector3.right * 0.015f * c),
                                  hit.point - new Vector2((-Vector2.right * 0.015f * c).x, (-Vector2.right * 0.015f * c).y), Color.magenta);
             }
         }
         hits = Physics2D.RaycastAll(transform.position, Vector2.right, 100);
         for (int i = 1; i < hits.Length; i++)
         {
             if (!hits[i].collider.isTrigger)
             {
                 hit = hits[i];
                 if (hit.collider.gameObject.tag == "cell")
                 {
                     hit.collider.gameObject.GetComponent <CellMover>().health -= 2.5f;
                 }
                 break;
             }
         }
         if (hit.collider != null && !hit.collider.isTrigger)
         {
             for (int c = 0; c < 10; c++)
             {
                 GLDebug.DrawLine(transform.position + new Vector3(1, 0, 0) + (Vector3.up * 0.015f * c),
                                  hit.point + new Vector2((Vector2.up * 0.015f * c).x, (Vector2.up * 0.015f * c).y), Color.magenta);
                 GLDebug.DrawLine(transform.position + new Vector3(1, 0, 0) - (Vector3.up * 0.015f * c),
                                  hit.point - new Vector2((Vector2.up * 0.015f * c).x, (Vector2.up * 0.015f * c).y), Color.magenta);
             }
         }
         hits = Physics2D.RaycastAll(transform.position, -Vector2.right, 100);
         for (int i = 1; i < hits.Length; i++)
         {
             if (!hits[i].collider.isTrigger)
             {
                 hit = hits[i];
                 if (hit.collider.gameObject.tag == "cell")
                 {
                     hit.collider.gameObject.GetComponent <CellMover>().health -= 2.5f;
                 }
                 break;
             }
         }
         if (hit.collider != null && !hit.collider.isTrigger)
         {
             for (int c = 0; c < 10; c++)
             {
                 GLDebug.DrawLine(transform.position + new Vector3(-1, 0, 0) + (-Vector3.up * 0.015f * c),
                                  hit.point + new Vector2((-Vector2.up * 0.015f * c).x, (-Vector2.up * 0.015f * c).y), Color.magenta);
                 GLDebug.DrawLine(transform.position + new Vector3(-1, 0, 0) - (-Vector3.up * 0.015f * c),
                                  hit.point - new Vector2((-Vector2.up * 0.015f * c).x, (-Vector2.up * 0.015f * c).y), Color.magenta);
             }
         }
         yield return(new WaitForSeconds(secondsBreak));
     }
 }
Ejemplo n.º 15
0
 public virtual void DrawLine(Vector3 startPos, Vector3 endPos)
 {
     GLDebug.DrawLine(startPos, endPos, lineColor, 0, true);
 }
    void DrawBoundingVolume(CustomCollider one, Color color, bool forceDraw = false, CustomCollider.ColliderType cType = CustomCollider.ColliderType.Box, CollisionMode mode = CollisionMode.SAT)
    {
        if (showBoundingVolumes.isOn || forceDraw)
        {
            if (mode == CollisionMode.AABB)
            {
                var xMin1 = one.transform.position.x + one.colliderOffset.x -
                            (one.colliderSize.x * one.transform.lossyScale.x) / 2;
                var xMax1 = one.transform.position.x + one.colliderOffset.x +
                            (one.colliderSize.x * one.transform.lossyScale.x) / 2;
                var yMin1 = one.transform.position.y + one.colliderOffset.y -
                            (one.colliderSize.y * one.transform.lossyScale.y) / 2;
                var yMax1 = one.transform.position.y + one.colliderOffset.y +
                            (one.colliderSize.y * one.transform.lossyScale.y) / 2;
                var zMin1 = one.transform.position.z + one.colliderOffset.z -
                            (one.colliderSize.z * one.transform.lossyScale.z) / 2;
                var zMax1 = one.transform.position.z + one.colliderOffset.z +
                            (one.colliderSize.z * one.transform.lossyScale.z) / 2;


                GLDebug.DrawLine(new Vector3(xMin1, yMin1, zMin1), new Vector3(xMax1, yMin1, zMin1), color,
                                 Time.deltaTime, true);
                GLDebug.DrawLine(new Vector3(xMin1, yMin1, zMax1), new Vector3(xMin1, yMin1, zMin1), color,
                                 Time.deltaTime, true);
                GLDebug.DrawLine(new Vector3(xMin1, yMin1, zMax1), new Vector3(xMax1, yMin1, zMax1), color,
                                 Time.deltaTime, true);
                GLDebug.DrawLine(new Vector3(xMax1, yMin1, zMax1), new Vector3(xMax1, yMin1, zMin1), color,
                                 Time.deltaTime, true);
                GLDebug.DrawLine(new Vector3(xMin1, yMin1, zMax1), new Vector3(xMin1, yMax1, zMax1), color,
                                 Time.deltaTime, true);
                GLDebug.DrawLine(new Vector3(xMax1, yMin1, zMin1), new Vector3(xMax1, yMax1, zMin1), color,
                                 Time.deltaTime, true);
                GLDebug.DrawLine(new Vector3(xMin1, yMax1, zMin1), new Vector3(xMax1, yMax1, zMin1), color,
                                 Time.deltaTime, true);
                GLDebug.DrawLine(new Vector3(xMin1, yMax1, zMax1), new Vector3(xMin1, yMax1, zMin1), color,
                                 Time.deltaTime, true);
                GLDebug.DrawLine(new Vector3(xMin1, yMax1, zMax1), new Vector3(xMax1, yMax1, zMax1), color,
                                 Time.deltaTime, true);
                GLDebug.DrawLine(new Vector3(xMax1, yMax1, zMax1), new Vector3(xMax1, yMax1, zMin1), color,
                                 Time.deltaTime, true);
                GLDebug.DrawLine(new Vector3(xMax1, yMin1, zMax1), new Vector3(xMax1, yMax1, zMax1), color,
                                 Time.deltaTime, true);
                GLDebug.DrawLine(new Vector3(xMax1, yMin1, zMax1), new Vector3(xMax1, yMax1, zMax1), color,
                                 Time.deltaTime, true);
            }
            else
            {
                if (one.colliderType == CustomCollider.ColliderType.Box)
                {
                    var box = ((CustomBoxCollider)one).GetOrientedBoxBounds();
                    GLDebug.DrawLine(box.dot1, box.dot2, color, Time.deltaTime, true);
                    GLDebug.DrawLine(box.dot2, box.dot6, color, Time.deltaTime, true);
                    GLDebug.DrawLine(box.dot5, box.dot6, color, Time.deltaTime, true);
                    GLDebug.DrawLine(box.dot5, box.dot1, color, Time.deltaTime, true);

                    GLDebug.DrawLine(box.dot4, box.dot8, color, Time.deltaTime, true);
                    GLDebug.DrawLine(box.dot3, box.dot7, color, Time.deltaTime, true);
                    GLDebug.DrawLine(box.dot4, box.dot3, color, Time.deltaTime, true);
                    GLDebug.DrawLine(box.dot8, box.dot7, color, Time.deltaTime, true);

                    GLDebug.DrawLine(box.dot1, box.dot4, color, Time.deltaTime, true);
                    GLDebug.DrawLine(box.dot2, box.dot3, color, Time.deltaTime, true);
                    GLDebug.DrawLine(box.dot6, box.dot7, color, Time.deltaTime, true);
                    GLDebug.DrawLine(box.dot5, box.dot8, color, Time.deltaTime, true);
                }
                else if (one.colliderType == CustomCollider.ColliderType.Sphere)
                {
                    var sphere = ((CustomSphereCollider)one);

                    Vector3 previousDirection = sphere.U().normalized;
                    for (int x = 0; x <= 20; x++)
                    {
                        Vector3 start        = sphere.transform.position + previousDirection * sphere.radius;
                        Vector3 newDirection = Quaternion.Euler(0, x * (360 / 20), 0) * sphere.U();
                        Vector3 end          = sphere.transform.position + newDirection.normalized * sphere.radius;
                        previousDirection = newDirection;
                        GLDebug.DrawLine(start, end, color, Time.deltaTime, true);
                    }
                    previousDirection = sphere.V().normalized;
                    for (int x = 0; x <= 20; x++)
                    {
                        Vector3 start        = sphere.transform.position + previousDirection * sphere.radius;
                        Vector3 newDirection = Quaternion.Euler(0, 0, x * (360 / 20)) * sphere.V();
                        Vector3 end          = sphere.transform.position + newDirection.normalized * sphere.radius;
                        previousDirection = newDirection;
                        GLDebug.DrawLine(start, end, color, Time.deltaTime, true);
                    }
                    previousDirection = sphere.W().normalized;
                    for (int x = 0; x <= 20; x++)
                    {
                        Vector3 start        = sphere.transform.position + previousDirection * sphere.radius;
                        Vector3 newDirection = Quaternion.Euler(x * (360 / 20), 0, 0) * sphere.W();
                        Vector3 end          = sphere.transform.position + newDirection.normalized * sphere.radius;
                        previousDirection = newDirection;
                        GLDebug.DrawLine(start, end, color, Time.deltaTime, true);
                    }
                }
            }
        }
    }
Ejemplo n.º 17
0
    private void Update()
    {
        if (!Main.DEBUG)
        {
            return;
        }

        int     i = ((int)this.transform.position.x / 10) * 10;
        int     j = ((int)this.transform.position.z / 10) * 10;
        Vector3 k = new Vector3(i, 0, j);

        // set colours
        Color dimColor    = new Color(gizmoLineColor.r, gizmoLineColor.g, gizmoLineColor.b, 0.25f * gizmoLineColor.a);
        Color brightColor = Color.Lerp(Color.white, gizmoLineColor, 0.75f);

        Color drawColor;

        // draw the horizontal lines
        for (int x = minX; x < maxX + 1; x++)
        {
            // find major lines
            drawColor = (x % gizmoMajorLines == 0 ? gizmoLineColor : dimColor);
            if (x == 0)
            {
                drawColor = brightColor;
            }

            Vector3 pos1 = new Vector3(x, minY, 0) * gridScale;
            Vector3 pos2 = new Vector3(x, maxY, 0) * gridScale;

            // convert to topdown/overhead units if necessary
            if (topDownGrid)
            {
                pos1 = new Vector3(pos1.x, 0, pos1.y);
                pos2 = new Vector3(pos2.x, 0, pos2.y);
            }

            GLDebug.DrawLine((gridOffset + pos1) + k, (gridOffset + pos2) + k, drawColor, 0, true);
        }

        // draw the vertical lines
        for (int y = minY; y < maxY + 1; y++)
        {
            // find major lines
            drawColor = (y % gizmoMajorLines == 0 ? gizmoLineColor : dimColor);
            if (y == 0)
            {
                drawColor = brightColor;
            }

            Vector3 pos1 = new Vector3(minX, y, 0) * gridScale;
            Vector3 pos2 = new Vector3(maxX, y, 0) * gridScale;

            // convert to topdown/overhead units if necessary
            if (topDownGrid)
            {
                pos1 = new Vector3(pos1.x, 0, pos1.y);
                pos2 = new Vector3(pos2.x, 0, pos2.y);
            }

            GLDebug.DrawLine((gridOffset + pos1) + k, (gridOffset + pos2) + k, drawColor, 0, true);
        }
    }
Ejemplo n.º 18
0
    public IEnumerator Laser()
    {
        while (true)
        {
            if ((rotation.sqrMagnitude > 0 && tag == "MyGun") && ((this.gameObject.tag != "MyGun" && GetComponentInParent <EnemyBehaviour>().seePlayer) || !player.GetComponent <CellMover>().isBigLaserFiring))
            {
                RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, transform.rotation * Vector2.up, 100);
                for (int i = 1; i < hits.Length; i++)
                {
                    if (!hits[i].collider.isTrigger && hits[i].collider.gameObject.tag != "drop")
                    {
                        hit = hits[i];
                        if (hit.collider.gameObject.tag == "enemy")
                        {
                            if (hasDamagator && Random.Range(0, 9) == 0)
                            {
                                hit.collider.gameObject.GetComponent <EnemyBehaviour>().health -= damage;
                            }
                            hit.collider.gameObject.GetComponent <EnemyBehaviour>().health -= damage;
                        }
                        else if (hit.collider.gameObject.tag == "cell" && tag != "MyGun")
                        {
                            if (hasDamagator && Random.Range(0, 9) == 0)
                            {
                                hit.collider.gameObject.GetComponent <CellMover>().health -= damage * (1 - hit.collider.gameObject.GetComponent <CellMover>().defense);
                            }
                            hit.collider.gameObject.GetComponent <CellMover>().health -= damage * (1 - hit.collider.gameObject.GetComponent <CellMover>().defense);
                        }
                        break;
                    }
                }

                if (hit.collider != null && !hit.collider.isTrigger)
                {
                    if (FirstFrameShooting)
                    {
                        EndOfLaserClone = Instantiate(EndOfLaser, hit.point, Quaternion.LookRotation(hit.point - new Vector2(transform.position.x, transform.position.y))) as GameObject;
                        EndOfLaserClone.GetComponent <SpriteRenderer>().color = color;
                    }
                    EndOfLaserClone.transform.position = hit.point;
                    EndOfLaserClone.transform.rotation = Quaternion.LookRotation(Vector3.forward, hit.point - new Vector2(transform.position.x, transform.position.y));
                    for (int c = 0; c < thickness; c++)
                    {
                        GLDebug.DrawLine(transform.position + transform.rotation * (new Vector3(0, lengthOfGun, 0)) + (transform.rotation * Vector3.right * 0.015f * c),
                                         hit.point + new Vector2((transform.rotation * Vector2.right * 0.015f * c).x, (transform.rotation * Vector2.right * 0.015f * c).y), color);
                        GLDebug.DrawLine(transform.position + transform.rotation * (new Vector3(0, lengthOfGun, 0)) - (transform.rotation * Vector3.right * 0.015f * c),
                                         hit.point - new Vector2((transform.rotation * Vector2.right * 0.015f * c).x, (transform.rotation * Vector2.right * 0.015f * c).y), color);
                    }
                }
/////////////Prisma//////////////
                if (hasPrism)
                {
                    if (!prismJustSet)
                    {
                        damage      /= 3;
                        prismJustSet = true;
                        thickness    = 1;
                    }
                    hits = Physics2D.RaycastAll(transform.position, transform.rotation * Quaternion.Euler(0, 0, Random.Range(0f, seporatorSpreading)) * Vector2.up, 100);
                    for (int i = 1; i < hits.Length; i++)
                    {
                        if (!hits[i].collider.isTrigger && hits[i].collider.gameObject.tag != "drop")
                        {
                            hit = hits[i];
                            if (hit.collider.gameObject.tag == "enemy")
                            {
                                hit.collider.gameObject.GetComponent <EnemyBehaviour>().health -= damage;
                            }
                            else if (hit.collider.gameObject.tag == "cell" && tag != "MyGun")
                            {
                                hit.collider.gameObject.GetComponent <CellMover>().health -= damage;
                            }
                            break;
                        }
                    }
                    if (hit.collider != null && !hit.collider.isTrigger)
                    {
                        for (int c = 0; c < thickness; c++)
                        {
                            GLDebug.DrawLine(transform.position + transform.rotation * (new Vector3(0, lengthOfGun, 0)) + (transform.rotation * Vector3.right * 0.015f * c),
                                             hit.point + new Vector2((transform.rotation * Vector2.right * 0.015f * c).x, (transform.rotation * Vector2.right * 0.015f * c).y), color);
                            GLDebug.DrawLine(transform.position + transform.rotation * (new Vector3(0, lengthOfGun, 0)) - (transform.rotation * Vector3.right * 0.015f * c),
                                             hit.point - new Vector2((transform.rotation * Vector2.right * 0.015f * c).x, (transform.rotation * Vector2.right * 0.015f * c).y), color);
                        }
                    }
                    hits = Physics2D.RaycastAll(transform.position, transform.rotation * Quaternion.Euler(0, 0, Random.Range(-seporatorSpreading, 0f)) * Vector2.up, 100);
                    for (int i = 1; i < hits.Length; i++)
                    {
                        if (!hits[i].collider.isTrigger && hits[i].collider.gameObject.tag != "drop")
                        {
                            hit = hits[i];
                            if (hit.collider.gameObject.tag == "enemy")
                            {
                                hit.collider.gameObject.GetComponent <EnemyBehaviour>().health -= damage;
                            }
                            else if (hit.collider.gameObject.tag == "cell" && tag != "MyGun")
                            {
                                hit.collider.gameObject.GetComponent <CellMover>().health -= damage * (1 - hit.collider.gameObject.GetComponent <CellMover>().defense);
                            }
                            break;
                        }
                    }

                    if (hit.collider != null && !hit.collider.isTrigger)
                    {
                        for (int c = 0; c < thickness; c++)
                        {
                            GLDebug.DrawLine(transform.position + transform.rotation * (new Vector3(0, lengthOfGun, 0)) + (transform.rotation * Vector3.right * 0.015f * c),
                                             hit.point + new Vector2((transform.rotation * Vector2.right * 0.015f * c).x, (transform.rotation * Vector2.right * 0.015f * c).y), color);
                            GLDebug.DrawLine(transform.position + transform.rotation * (new Vector3(0, lengthOfGun, 0)) - (transform.rotation * Vector3.right * 0.015f * c),
                                             hit.point - new Vector2((transform.rotation * Vector2.right * 0.015f * c).x, (transform.rotation * Vector2.right * 0.015f * c).y), color);
                        }
                    }
                }
                FirstFrameShooting = false;
            }
            else
            {
                FirstFrameShooting = true;
                Destroy(EndOfLaserClone);
            }
            yield return(0);
        }
    }
Ejemplo n.º 19
0
    void Update()
    {
        if (health > maxHealth)
        {
            health = maxHealth;
        }
        if (energy > maxEnergy)
        {
            energy = maxEnergy;
        }
        energySlider.value = energy;
        healthSlider.value = health;
        level = PlayerPrefs.GetFloat("level");
        if (findedRoom == 1)
        {
            findedRoom = 2;
            rooms      = GameObject.FindGameObjectsWithTag("room");
            rooms      = GameObject.FindGameObjectsWithTag("room");
            for (int i = 0; i < rooms.Length; i++)
            {
                if (rooms[i].name == "StartRoom(Clone)")
                {
                    transform.position = rooms[i].transform.position;
                    room = rooms[i];
                    break;
                }
            }
        }
        if (findedRoom == 2)
        {
            rooms = GameObject.FindGameObjectsWithTag("room");
            if (rooms.Length != 0)
            {
                for (int i = 0; i < rooms.Length; i++)
                {
                    if (Mathf.Abs(rooms [i].transform.position.x - transform.position.x) < rooms [i].GetComponent <RoomScript> ().width&&
                        Mathf.Abs(rooms [i].transform.position.y - transform.position.y) < rooms [i].GetComponent <RoomScript> ().height)
                    {
                        room = rooms [i];
                        break;
                    }
                    if (i == rooms.Length - 1 && GameObject.Find("Transaction Camera(Clone)") == null)
                    {
                        for (int b = 0; b < rooms.Length; b++)
                        {
                            if (rooms[b].name == "StartRoom(Clone)")
                            {
                                transform.position = rooms[b].transform.position;
                                room = rooms[b];
                                break;
                            }
                        }
                    }
                }
            }
            movement = new Vector3(MovementJoystick.GetAxis("Horizontal"), MovementJoystick.GetAxis("Vertical"), 0f);
                #if UNITY_EDITOR
            movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0f);
                #endif
            rigidbody2D.AddForce(movement * movementSpeed * Time.deltaTime * 60);
            if (movement.sqrMagnitude != 0)
            {
                transform.rotation = Quaternion.Lerp(transform.rotation,
                                                     Quaternion.LookRotation(Vector3.forward, movement),
                                                     Time.deltaTime * RotationSpeed);
            }
            if (rigidbody2D.velocity.sqrMagnitude > 0.01f)
            {
                int index = (int)(Time.timeSinceLevelLoad * framesPerSecond);
                index = index % sprites.Length;
                spriteRenderer.sprite = sprites [index];
            }
            if (health <= 0 && !GodMode)
            {
                Application.LoadLevel("Menu");
                PlayerPrefs.SetInt("DidLosed", 1);
                PlayerPrefs.SetFloat("level", 1);
                PlayerPrefs.SetInt("HasSeporator", 0);
                PlayerPrefs.SetInt("HasDamagator", 0);
                PlayerPrefs.SetInt("NumberOfDNA", 0);
            }
        }
        levelText.text = level.ToString();

/////////////////////////////////////////////////////////////BIGLASER////////////////////////////////////////////////////////////////////////////////////////////

        if (isBigLaserFiring)
        {
            k += Time.deltaTime;
            if (k >= BigShotDuration)
            {
                isBigLaserFiring = false;
                k = 0;
            }
            if (k >= 1f)
            {
                GameObject     gun      = GameObject.FindGameObjectWithTag("MyGun");
                Quaternion     rotation = gun.transform.rotation;
                Vector3        position = gun.transform.position;
                RaycastHit2D[] hits     = Physics2D.RaycastAll(position, rotation * Vector2.up, 100);
                for (int i = 1; i < hits.Length; i++)
                {
                    if (!hits [i].collider.isTrigger && hits [i].collider.gameObject.tag != "barrier" && hits [i].collider.gameObject.tag != "dynamicBarrier" && hits[i].collider.gameObject.tag != "drop")
                    {
                        hit = hits [i];
                        if (hit.collider.gameObject.tag == "enemy")
                        {
                            hit.collider.gameObject.GetComponent <EnemyBehaviour> ().health -= 10;
                        }
                        break;
                    }
                }
                if (hit.collider != null && !hit.collider.isTrigger)
                {
                    if (FirstFrameShooting)
                    {
                        EndOfLaserClone = Instantiate(EndOfLaser, hit.point, Quaternion.LookRotation(hit.point - new Vector2(transform.position.x, transform.position.y))) as GameObject;
                        EndOfLaserClone.GetComponent <SpriteRenderer>().color = Color.magenta;
                    }
                    EndOfLaserClone.transform.position = hit.point;
                    EndOfLaserClone.transform.rotation = Quaternion.LookRotation(Vector3.forward, hit.point - new Vector2(transform.position.x, transform.position.y));
                    for (int c = 0; c < 5; c++)
                    {
                        GLDebug.DrawLine(position + (rotation * Vector3.right * 0.015f * c),
                                         hit.point + new Vector2((rotation * Vector2.right * 0.015f * c).x, (rotation * Vector2.right * 0.015f * c).y), Color.magenta);
                        GLDebug.DrawLine(position - (rotation * Vector3.right * 0.015f * c),
                                         hit.point - new Vector2((rotation * Vector2.right * 0.015f * c).x, (rotation * Vector2.right * 0.015f * c).y), Color.magenta);
                    }
                }
                FirstFrameShooting = false;
            }
        }
        else
        {
            FirstFrameShooting = true;
            Destroy(EndOfLaserClone);
        }
        //	StartCoroutine (GameObject.FindGameObjectWithTag("MyGun").GetComponent<GunScript>().StartCoroutine (MachinGun()));
    }
Ejemplo n.º 20
0
 public void drawDebug()
 {
     GLDebug.DrawLine(this.agent.transform.position.setY(0.5f), this.agent.destination.setY(0.5f), Color.cyan);
 }
 public virtual void DrawLine()
 {
     GLDebug.DrawLine(startPos, endPos, lineColor, 0, true);
 }