コード例 #1
0
        private void OnCollisionEnter(Collision collision)
        {
            AsteroidDeformation deformer = collision.transform.GetComponent <AsteroidDeformation>();

            if (deformer != null)
            {
                deformer.Hit(collision.contacts[0].point);
            }
        }
コード例 #2
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);
                }
            }
        }
コード例 #3
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;
                    }
                }
            }
        }