Пример #1
0
        void InitFruit(bool isbomb)
        {
            int   RangeFruit = Random.Range(0, fruits.Length);
            float x          = Random.Range(-4.5f, 4.5f);

            z += 1.5f;
            if (z >= 6.0)
            {
                z = 0;
            }

            GameObject gameOb;
            Vector3    vet      = transform.position + new Vector3(x, StartY, z);
            Vector3    scaleVet = Vector3.one;

            if (!isbomb)
            {
                switch (RangeFruit)
                {
                case 0:
                    poolCurrentFruit = poolApple;
                    scaleVet         = Vector3.one * 1500;
                    break;

                case 1:
                    poolCurrentFruit = poolPineapple;
                    scaleVet         = Vector3.one * 400;
                    //菠萝
                    break;

                case 2:              //西瓜
                    poolCurrentFruit = poolWatermelon;
                    scaleVet         = Vector3.one * 600;
                    break;

                default: break;
                }
                gameOb = poolCurrentFruit.GetItem();
                if (gameOb == null)
                {
                    gameOb = Instantiate(fruits[RangeFruit], vet, Random.rotation);
                    // gameOb.transform.parent = gameObject.transform;
                    poolCurrentFruit.Add(gameOb);
                }
                gameOb.SetActive(true);
                // gameOb.SetActive(false);
                gameOb.transform.position      = vet;
                gameOb.transform.localScale    = scaleVet;
                gameOb.transform.localRotation = Quaternion.identity;
                //gameOb = GameObject.Instantiate(fruits[RangeFruit], vet, Random.rotation);
            }
            else
            {
                gameOb = Instantiate(bomb, vet, Random.rotation);
            }

            float power     = Random.Range(1.6f, 1.7f) * -Physics.gravity.y * 1.5f * powerMod;
            var   direction = new Vector3(-x * 0.05f * Random.Range(0.32f, 0.81f), 1.0f);

            direction.z = 0.0f;
            gameOb.GetComponent <Rigidbody>().velocity = direction * power;
            gameOb.GetComponent <Rigidbody>().AddTorque(Random.onUnitSphere * 0.1f, ForceMode.Impulse);

            GetComponent <AudioSource>().PlayOneShot(sfx, 2);
        }