Changing eye texture using bools

  • Hello,

I’m attempting to change the texture of an NPC’s eyes using bools. This is the script I’ve written to check a bool from another script and change the texture if it is true. I can use the Input function to change the eye texture, but all of the bool checking lines I wrote are not working.

using UnityEngine; using System.Collections;

public class ChangeEyes : MonoBehaviour { public Texture[ ] textures; public int currentTexture;

  • // Use this for initialization
  • voidStart()
  • {
  • }
  • // Update is called once per frame
  • voidUpdate()
  • {
  • //if (Input.GetKeyDown(KeyCode.Space))
  • //if (cry == true)
  • //if (GameObject.Find(“Chao”).GetComponent().cry == true)
  • if(gameObject.GetComponent().cry)
  • {
  • currentTexture++;
  • currentTexture %= textures.Length;
  • GetComponent().material.mainTexture = textures[currentTexture];
  • }
  • }

}

Any help is appreciated.

I assume ChaoNeeds is on the same gameObject this script is on?
try this:

ChaoNeeds cn;
void Start()
{
    cn = GetComponent<ChaoNeeds>();
}
void Update()
{
    if(cn == null)
    {
        Debug.Log("The script wasn't found");
        return;
    }
    if(cn.cry)
    {
    //do the texture thing
    }
}