private IEnumerator GenerateBodies(Body[] bodies, int startIndex, int endIndex)
        {
            yield return Ninja.JumpToUnity;

            for (int i = startIndex; i < endIndex; i++)
            {
                Vector3 bodyPos = bodies[i].GetPosition() * Dispersion;
                GameObject obj = Instantiate(Prefab, bodyPos, Random.rotation);
                AsteroidDeformation deform = obj.GetComponent<AsteroidDeformation>();
                
                Task task;
                yield return this.StartCoroutineAsync(deform.Deform(), out task);
                yield return StartCoroutine(task.Wait());

                AutoRotate autoRotate = obj.GetComponent<AutoRotate>();
                autoRotate.speed = new Vector3(
                    Random.Range(MinRotationForce, MaxRotationForce),
                    Random.Range(MinRotationForce, MaxRotationForce),
                    Random.Range(MinRotationForce, MaxRotationForce)
                    );

                Vector3 scaleVector = new Vector3(
                    Random.Range(MinScaleVariance, MaxScaleVariance),
                    Random.Range(MinScaleVariance, MaxScaleVariance),
                    Random.Range(MinScaleVariance, MaxScaleVariance)
                    ) * bodies[i].Size * Random.Range(MinArbitraryScaler, MaxArbitraryScaler);
                obj.transform.localScale = scaleVector;

                AsteroidDetailer detailer = obj.GetComponent<AsteroidDetailer>();
                detailer.Detail();

                obj.transform.SetParent(transform);
            }
        }
Exemplo n.º 2
0
        private void OnCollisionEnter(Collision collision)
        {
            AsteroidDeformation deformer = collision.transform.GetComponent <AsteroidDeformation>();

            if (deformer != null)
            {
                deformer.Hit(collision.contacts[0].point);
            }
        }
Exemplo n.º 3
0
        private void Hit(Vector3 mousePosition)
        {
            Ray ray = cam.ScreenPointToRay(mousePosition);

            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                AsteroidDeformation deformer = hit.transform.GetComponent <AsteroidDeformation>();

                if (deformer != null)
                {
                    deformer.Hit(hit.point);
                }
            }
        }
Exemplo n.º 4
0
        private void Shoot()
        {
            shootAccumulatedTime += Time.deltaTime;

            RaycastHit hit;

            if (Physics.Raycast(Laser.transform.position, Laser.transform.TransformDirection(Vector3.forward), out hit, Laser.EndPos.z))
            {
                AsteroidDeformation deformer = hit.transform.GetComponent <AsteroidDeformation>();

                if (deformer != null)
                {
                    deformer.Hit(hit.point);

                    if (shootAccumulatedTime > HitSound.clip.length + 0.001f)
                    {
                        HitSound.Stop();
                        HitSound.pitch = Random.Range(-1.0f, 1.5f);
                        HitSound.Play();
                        shootAccumulatedTime = 0;
                    }
                }
            }
        }