private void OnCollisionEnter(Collision collision) { AsteroidDeformation deformer = collision.transform.GetComponent <AsteroidDeformation>(); if (deformer != null) { deformer.Hit(collision.contacts[0].point); } }
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); } } }
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; } } } }