为什么我得到'IsFinite(outDistanceForSort)'Unity

时间:2018-12-07 19:35:42

标签: c# unity3d

出现此错误:“ IsFinite(outDistanceForSort)”,您知道伙计们我的代码有什么问题吗?

问题是有时球会自行破坏,有时速度会降低,或者当球与其他物体碰撞时,它会以怪异的动作前进和后退!

这是我的代码:

    private void Start()
    {
        BallCollectEffect.Stop();
        FireWorksEffect.Stop();
        ContinueButton.SetActive(false);
        rb = GetComponent<Rigidbody>();

        count = 0;
        setcountText();
        winText.text = "";
        audioSource1 = GetComponent<AudioSource>();
        audioSource2 = GetComponent<AudioSource>();
    }

    void FixedUpdate () {

        //rb.AddForce(Vector3.forward * speed * Time.deltaTime);
        transform.position += Vector3.forward * Time.deltaTime * speed;
        //rb.AddForce(0, 0, speed *Time.deltaTime);
        //rb.velocity = transform.forward * speed;
        //rb.MovePosition(transform.position + transform.forward * speed);
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag ("Enemy"))
        {
            audioSource2.Play();
            SpeedEffect.Stop();
            rb.gameObject.SetActive(false);
            Instantiate(BallDestroyEffect, transform.position, transform.rotation);
            FindObjectOfType<GameManager>().EndGame();

        }
        if (collision.gameObject.CompareTag("End"))
        {
            ContinueButton.SetActive(true);
            winText.text = "Level Completed!";
            SpeedEffect.Stop();
            FireWorksEffect.Play();
        }
        if(collision.gameObject.CompareTag("Glass"))
        {
            audioSource1.Play();
            count = count + 3;
            setcountText();
            BallCollectEffect.Play();
            if (FloatingTextPrefab)
            {
                ShowFloatingText();
            }
        }
    }

    void ShowFloatingText()
    {
        Instantiate(FloatingTextPrefab, transform.position, Quaternion.identity, transform);
    }


    void setcountText ()  {
        countText.text = count.ToString();
    }
}

0 个答案:

没有答案