protected override void Awake() { base.Awake(); bullet = transform.Find("Cartridge").gameObject; bullet.SetActive(false); trigger = transform.Find("Trigger").gameObject; slide = transform.Find("Slide").GetComponent <MagazineFedPistol_Slide>(); slideRigidbody = slide.GetComponent <Rigidbody>(); slideCollider = slide.GetComponent <Collider>(); }
//Using this one! private void fireRaycast() { RaycastHit hit; Rigidbody slideRigidBody = slide.GetComponent(typeof(Rigidbody)) as Rigidbody; slideRigidbody.AddForce(0, 0, 0, ForceMode.Impulse); if (roundInChamber) { if (Physics.Raycast(this.gameObject.transform.GetChild(8).position, transform.TransformDirection(Vector3.forward), out hit, shotRange)) { Debug.Log("hit something, in fact hit " + hit.collider.gameObject.name); GameObject clone = Instantiate(bullet, hit.point, Quaternion.identity) as GameObject; clone.SetActive(true); } } else { //*click* } }