void Update() { mouse_coord = new Vector3(Input.mousePosition.x - (Screen.width / 2f), Input.mousePosition.y - (Screen.height / 2f), 0f); StartCoroutine("GetVectorDirection"); // If left mouse button is clicked, then a Raycast will be activated if (Input.GetButtonDown("Fire1")) { RaycastHit shot; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // Mouse cursor dictates direction of shot if (Physics.Raycast(ray, out shot)) { // Shoot object along with raycast Rigidbody projectile_clone = Instantiate(projectile, ray.origin, Quaternion.identity); projectile_clone.velocity = transform.TransformDirection(empty_object.transform.forward * pwr); // If ball is hit, then it will be destoryed if (shot.transform.gameObject.tag == "ball") { Debug.Log("Ball spotted!"); Destroy(shot.transform.gameObject); GameScore.AddScore(5); } } } }
private void OnCollisionEnter(Collision collision) { // If projectile hits a ball, then it destroys the ball if (collision.gameObject.tag == "ball") { Destroy(collision.transform.gameObject); GameScore.AddScore(5); } }
void Update() { distance = Vector3.Distance(truck.transform.position, transform.position); // check distance between the two objects if (distance < 10f) { Vector3 pos = this.transform.position; Destroy(this.gameObject); //Destroy this object the create "Explosion" in same position for (int i = 0; i < 300; i++) { Instantiate(cube, pos, Quaternion.Euler(Mathf.Sin(Time.time), Mathf.Sin(Time.time), Mathf.Sin(Time.time))); } GameScore.AddScore(50); // 50 pts for discovering the explosive cube } }
void Update() { distance = Vector3.Distance(obj.transform.position, truck.transform.position); if (distance < desired_distance) { if (obj == GameObject.FindGameObjectWithTag("dog") && !dog_found) { GameScore.AddScore(50); dog_found = true; } //If less than specified desired distance create popup text_mesh.enabled = true; } else { //do not create popup text_mesh.enabled = false; } }