I have this line of code:
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
private GameObject weapGun;
private GameObject weapMelee;
void Awake(){
weapGun = GameObject.FindGameObjectWithTag("Gun");
weapMelee = GameObject.FindGameObjectWithTag("Melee");
Debug.Log(weapGun);
Debug.Log(weapMelee);
}
void Update(){
if(Input.GetKeyDown("1")){
weapGun.GetComponent<SpriteRenderer>().enabled = true;
weapMelee.GetComponent<SpriteRenderer>().enabled = false;
}
if(Input.GetKeyDown("2")){
weapGun.GetComponent<SpriteRenderer>().enabled = false;
weapMelee.GetComponent<SpriteRenderer>().enabled = true;
}
}
}
I get no errors and the Debug.Log()'s return the correct GameObjects, but the "GetComponent().enabled = true/false; are not doing anything? Can anyone please point out my error.