I’m making my first multiplayer game, and much of the code is based off the official tutorial on it somewhere on the unity webpage, with modifications. Im trying to access a script called Health with GetComponent, but it dosent work, which dosent make sense because I kept all the needed parts of code from the tutorial. Heres the code for the bullet that is trying to get the Health script from whatever it hits. I know its the GetComponent because I have narrowed it down using Debug.Log.
void OnCollisionEnter(Collision collision)
{
Destroy(gameObject);
GameObject hit = collision.gameObject;
Health health = hit.GetComponent<Health>();
if (health != null)
{
health.TakeDamage(10);
}
else
{
Debug.Log("No Health Script Found");
}
}