示例#1
0
    void OnTriggerEnter2D(Collider2D hit)
    {
        SoulBehavior soulBehavior = hit.GetComponent <SoulBehavior>();

        if (hit.gameObject == soulBeingLaunched && soulBehavior != null)
        {
            powerupHandler.HideIcons();
            ChoseAnyPowerUp();
            shatterParticles.Play();
            DeterminePowerup();
            soulBehavior.ReturnToPool();
        }
    }
    public IEnumerator PrimeSlingshot(GameObject whichSoul)
    {
        currentSoulBehaviour = whichSoul.GetComponent <SoulBehavior>();
        PrimingSoul();
        if (!zoomed)
        {
            //  ZoomOnPlayer();
        }
        //Debug.Log("Priming!");
        priming = true;
        currentSoulBehaviour.beingPrimed = true;
        mouseStartPosition = Input.mousePosition;
        float   distance  = 0;
        Vector2 direction = new Vector2(0, 0);

        slingshotLineRenderer         = whichSoul.GetComponentInChildren <LineRenderer>();
        slingshotLineRenderer.enabled = true;
        FreezeTime.SlowdownTime(0.10f);
        while (true)
        {
            if (Input.GetMouseButtonUp(1))
            {
                break;
            }
            if (Input.GetMouseButtonDown(0))
            {
                //right click to cancel
                stillHeld = true;
                slingshotLineRenderer.enabled = false;
                yield break;
            }
            slingshotLineRenderer.SetPosition(0, whichSoul.transform.position);
            slingshotLineRenderer.SetPosition(1, Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y)));
            yield return(null);
        }
        slingshotLineRenderer.enabled = false;

        Vector2 mousePos           = Input.mousePosition;
        Vector2 mousePositionWorld = Camera.main.ScreenToWorldPoint(new Vector2(mousePos.x, mousePos.y));

        Rigidbody2D soulRigidbody = whichSoul.GetComponent <Rigidbody2D>();

        distance  = Vector2.Distance(whichSoul.transform.position, mousePositionWorld);
        direction = (Vector2)((Vector2)whichSoul.transform.position - mousePositionWorld);


        float velocity = distance * Mathf.Sqrt(elasticity / soulRigidbody.mass);

        velocity *= (10); //multiply to cancel out low timescale
        soulRigidbody.isKinematic = false;
        soulRigidbody.velocity    = (direction.normalized * velocity);

        //Debug.Log(pReference.rb.velocity);
        priming = false;
        currentSoulBehaviour.beingPrimed = false;
        currentSoulBehaviour.launching   = true;
        DonePrimingSoul();
        launching = true;
        LaunchingSoul(whichSoul);
        StartCoroutine(CountdownFromLaunch());
        //   StartCoroutine(PlotPath());
    }