GetComponent returns null
Hi im getting this really annoying problem that appears from no where. I have been developing this game for a really long time and suddenly a method that i have stop working and tells me that the getComponent that return the script from an object is null despite that i see that its working on the inspector.
here it is:
using UnityEngine; using System.Collections;
public class ScrCoger : MonoBehaviour {
private GameObject antorcha;
void Start(){
antorcha = GameObject.FindGameObjectWithTag ("Antorcha");
}
void OnTriggerStay2D(Collider2D temp){
if(temp.gameObject.tag == "Player" && Input.GetKeyDown(KeyCode.R)){
antorcha.GetComponent<ScrAntorcha>().activarAntorcha();
this.gameObject.SetActive(false);
}
}
}
So antorcha as a gameobject is not null but the "antorcha.GetComponent()" returns null and i dont know why in the past month this code was working.
So if anyone have an idea of what its happening please tell me. I appreciate anyone help. Sorry for my english, its not my native language, thanks.
Your answer
Follow this Question
Related Questions
GetComponent returning null inside script, but working well outside 0 Answers
Is it overkill to RequireComponent then check if GetComponent isnt Null in Awake? 1 Answer
NullReferenceException Help please :> 1 Answer
Custom Property Drawer never sets the property 0 Answers
Bullet Prefab Switch Help 0 Answers