My ray casts are clearly being shot out when I go into the game but the problem is that it’s not detecting the items I’ve tagged as Key or Door when it casts them. the key doesn’t get destroyed and the door doesn’t open.
using UnityEngine;
using System.Collections;
public class Keys : MonoBehaviour {
public float maxKey = 5;
public float curKey = 0;
void Update (){
if(Input.GetKeyDown(KeyCode.E)){ //If E is pressed
Debug.Log("Pressed");
RaycastHit hit;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast (transform.position, fwd, out hit, 10)) {// Sends out a raycast to check if something is in front of you
Debug.DrawRay(transform.position, fwd * 10, Color.green);
if(hit.transform.Equals("key")){ // If the object in front of you has the tag Key
Debug.Log("the Key Is There");
curKey += 1;
Destroy(hit.transform.root.gameObject);//Destroy Key Object
animation.Play("Door");
}else if(hit.transform.name.Equals("Door")){ //Checks if the gameobject you're looking at has the tag Door
if (curKey == 1)
Debug.Log("HasKey");
animation.Play ("New Animation"); //Calls the function Unlock on the door
curKey -=1;
}
}
}
}
}