Exemple #1
0
    void dig()
    {
        Vector2 shoulderPos = foregroundShoulder.position;

        if (!toolManager.rightOri)
        {
            shoulderPos = backgroundShoulder.position;
        }
        float      dist;
        GameObject obj = MouseOver(shoulderPos, out dist);

        if (obj == null || obj.transform.GetComponent <Collider2D>() == null)
        {
            return;
        }
        // Vector2 nearestPoint = obj.transform.GetComponent<Collider2D>().ClosestPoint(shoulderPos);


        if (dist <= reach)
        {
            asteroid ast = obj.GetComponent <asteroid>();
            if (ast != null)
            {
                if (hit != null)
                {
                    hit.Play();
                }
                pickaxeHit.transform.position = cam.ScreenToWorldPoint(Input.mousePosition);
                pickaxeHit.Play();
                ast.damage(strenth);
            }
        }
        //StartCoroutine("animatePick");
    }
    /// <summary>
    /// Sent when an incoming collider makes contact with this object's
    /// collider (2D physics only).
    /// </summary>
    /// <param name="other">The Collision2D data associated with this collision.</param>
    void OnCollisionEnter2D(Collision2D other)
    {
        asteroid astro = other.gameObject.GetComponent <asteroid>();

        if (astro != null)
        {
            astro.damage(damage);
        }
        if (layerMask == (layerMask | (1 << other.gameObject.layer)))
        {
            particles.Play();
            sprite.enabled     = false;
            col.enabled        = false;
            rb.velocity        = Vector2.zero;
            rb.angularVelocity = 0;
        }

        //Destroy(gameObject);
    }
Exemple #3
0
 public void laserStuff()
 {
     if (Input.GetButton("Fire1"))
     {
         laser.SetActive(true);
         RaycastHit2D hit = Physics2D.Raycast(laserOrigin.position, toolDir, 100, layerMask);
         if (hit.collider != null)
         {
             foreach (LineRenderer l in laserBeams)
             {
                 l.SetPosition(1, l.transform.InverseTransformPoint(hit.point));
                 end.position = hit.point;
                 end.up       = hit.normal;
                 end.gameObject.SetActive(true);
             }
             asteroid astro = hit.collider.GetComponent <asteroid>();
             if (astro != null)
             {
                 Vector2 pos  = astro.transform.position;
                 bool    boom = astro.damage(damagePerSecond * Time.deltaTime);
                 if (boom)
                 {
                     GameObject.Instantiate(explosion, pos, Quaternion.Euler(0, 0, Random.Range(0, 360)));
                     float shaky = Mathf.Clamp(-hit.distance * 0.1f + 1, 0.1f, 1f) * 0.7f;
                     shake.Shake(0.2f, shaky);
                 }
             }
         }
         else
         {
             foreach (LineRenderer l in laserBeams)
             {
                 l.SetPosition(1, Vector2.right * 100f);
                 end.gameObject.SetActive(false);
             }
         }
     }
     else
     {
         laser.SetActive(false);
     }
 }
Exemple #4
0
    void LateUpdate()
    {
        changeOldPos = true;
        Debug.DrawRay(shoulder.position, Vector2.up, Color.yellow);
        Vector2 mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
        // toolManager.focus doMath();

        Vector2 handpos = HandPos(mousePos);

        //rbHead.MovePosition(rbHead.position+(Vector2.right*0.1f));
        if (Input.GetButton("Fire1"))
        {
            normalSound.UnPause();
            toolManager.focus.position = GetCorrectedHandPos(handpos);
            drilling = true;
            drillHead.SetFloat("speed", drillSpeed);
            targetExtend = Mathf.Clamp(Vector2.Distance(shoulder.position, mousePos) - (r + R), 0, extendable);
            //head.localPosition = Vector2.right*(defaultExtend+targetExtend);
        }
        else
        {
            normalSound.Pause();
            toolManager.focus.position = handpos;
            drilling     = false;
            targetExtend = 0;
            drillHead.SetFloat("speed", 0);
        }
        Collider2D[] asteroids;
        touching = GetTouching(out asteroids);
        bool  h    = GetTouchingHinten();
        float plus = (Mathf.Sign(targetExtend - currentExtend) * Time.deltaTime) / (extendSpeed * extendable);
        bool  ok   = true;

        if (touching && !changeOldPos && switchWait == 0)
        {
            float lenny = (transform.InverseTransformPoint(oldPosition).x - (toolLength + currentExtend + (plus * extendable)));
            if (lenny < 0)
            {
                currentExtend      = Mathf.Clamp(currentExtend + (lenny - ((plus * extendable))), 0, extendable);
                head.localPosition = Vector2.right * (defaultExtend + currentExtend);
                rod.localScale     = Vector2.one + Vector2.up * (-0.9f + currentExtend);
                ok = false;
            }
        }
        if (currentExtend != targetExtend && ok)
        {
            float f = currentExtend / extendable;
            if (drilling)
            {
                if ((plus > 0 && touching) || (plus < 0 && h))
                {
                    ok = false;
                }
            }
            if (ok)
            {
                currentExtend = Mathf.Lerp(0, extendable, Mathf.Clamp01(f + plus));
                if ((plus > 0)?(currentExtend > targetExtend):(currentExtend < targetExtend))
                {
                    currentExtend = targetExtend;
                }
            }

            head.localPosition = Vector2.right * (defaultExtend + currentExtend);
            rod.localScale     = Vector2.one + Vector2.up * (-0.9f + currentExtend);
        }
        if (touching && drilling)
        {
            foreach (ParticleSystem pS in particles)
            {
                pS.Play();
                hitSound.UnPause();
            }

            foreach (Collider2D col in asteroids)
            {
                if (col != null)
                {
                    asteroid astro = col.GetComponent <asteroid>();
                    if (astro != null)
                    {
                        astro.damage(damagePerSecond * Time.deltaTime);
                    }
                }
            }
        }
        else
        {
            hitSound.Pause();
            foreach (ParticleSystem pS in particles)
            {
                pS.Stop();
            }
        }
        if (switchWait == 0 && changeOldPos)
        {
            oldPosition = transform.TransformPoint(Vector2.right * (toolLength + currentExtend));
        }

        if (switchWait > 0)
        {
            switchWait--;
        }
    }