The issue, I believe, rests on line 46 of my code. I raycast out, and in this version of the code:
using System.Collections;
public class FPscript : MonoBehaviour {
//public GameObject untitled;
float bulletImpulse = 100f;
bool test = false;
RaycastHit hitt;
void Start (){
}
void OnControllerColliderHit(ControllerColliderHit hit){
if (hit.gameObject.tag == "Key") {
test = true;
}
}
void Update (){
if (Input.GetKey(KeyCode.Escape)){
Application.Quit ();
}
//if(test == true){
//if( Input.GetButtonDown("Fire1") ) {
//Camera camm = Camera.main;
//GameObject thebullet = (GameObject)Instantiate(untitled, camm.transform.position + camm.transform.forward, camm.transform.rotation);
//thebullet.rigidbody.AddForce( camm.transform.forward * bulletImpulse, ForceMode.Impulse);
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if( Input.GetButtonDown("Fire1") ) {
if (Physics.Raycast(transform.position, fwd, 10)){
// if(hitt.collider.gameObject.tag == "Enemy"){
Debug.Log("Object Hit");
// }
}
}
}
}
I get a Debug.Log report, but when I take out the comments on the line that reads // if(hitt.collider.gameObject.tag == "Enemy"){
, nothing happens no matter what. I’m a little stumped, as I have triple checked and this seems to be the correct way to test what you hit. Any suggestions from anyone?