Find Component?

i tryed every thing noting worked can someone help me ?
i want to find my component myManager on Start every time my Zombie is spawn to access the script which is in the scene?
public float moveSpeed = 1.1f;
public AudioClip roar;
public GameManager myManager;
void Start(){
AudioSource.PlayClipAtPoint (roar,transform.position);
}
void Update () {
transform.Translate(new Vector3(1,0,0)moveSpeedTime.deltaTime);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == “Bullet”)
{
Destroy (gameObject,0.3f);
myManager.Score += 1;
}
}

}

If the GameManager is not attached to the GameObject this script is attached to, you have three solutions (one provided by @Stradigos, the simplest one by the way):

  • Call the GameObject.Find() or GameObject.FindWithTag() to get the object with the GameManager Script
  • Use the Singleton design pattern to get the reference of the script using a static function anywhere from your code.
  • Use public variables like you did with public GameManager myManager, just drag and drop the object with the GameManager script, and voilà !

In Awake() or Start(), you want to use GetComponent:

myManager = gameObject.GetComponent<GameManager>();