using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SetFire : MonoBehaviour { public Text txtMsg; public GameObject goTarget; public GameObject goBulletHole; public AudioClip HitSound; private AudioSource audioSource; // Use this for initialization void Start () { audioSource = GetComponent(); } // Update is called once per frame void Update () { if (Input.GetMouseButtonDown (0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { txtMsg.text = hit.point.ToString (); if (hit.transform.tag.ToString () == "target") { Quaternion qRot = goTarget.transform.rotation; goBulletHole.transform.rotation = qRot; goBulletHole.transform.position = hit.point + goTarget.transform.forward*0.2f; goBulletHole.gameObject.SetActive (true); audioSource.PlayOneShot(HitSound); } } } } }