So I have an object with a few children. I want to be able to disable/enable 2 of their SpriteRenderers via one of my scripts. I feel like I'm doing things right, but apparently I'm not. And yes, my game objects have the appropriate tags that are being searched for in my code. I'll paste the relevant bits of code below:
public bool isAiming = false; Animator playerAnim; GameObject arm; GameObject weapon; SpriteRenderer armRenderer; SpriteRenderer weaponRenderer; void Start() { playerAnim = gameObject.GetComponent<Animator>(); arm = GameObject.FindGameObjectWithTag("Arm"); weapon = GameObject.FindGameObjectWithTag("EquippedWeapon"); armRenderer = arm.GetComponent<SpriteRenderer>(); weaponRenderer = weapon.GetComponent<SpriteRenderer>(); } void Update() { CheckIfAiming(); } void CheckIfAiming() { if (Input.GetButton("Fire2")) // Holding right click { isAiming = true; armRenderer.enabled = true; weaponRenderer.enabled = true; playerAnim.SetBool("isAiming", isAiming); } else { isAiming = false; armRenderer.enabled = false; weaponRenderer.enabled = false; playerAnim.SetBool("isAiming", isAiming); } } What gives? I want to just enable the sprite rendering when I hold down the right mouse click. SetActive(false/true) is not an option as I still want code to affect them while they're not visible.
Am I just trying to access the SpriteRenderers incorrectly?