I had to write a code in the enemy script that when they collides with a bullet damage is taken. Now I want to change this int, (which defines the damage of the bullet) but how? I am getting errors.
enemy script:
public int bulletdamage;
public void dead()
{
Destroy(gameObject);
}
public void OnCollisionEnter(Collision collision)
{
if (collision.collider.CompareTag("bullet"))
{
Debug.Log("loluhit");
healthenemy -= bulletdamage;
if (healthenemy <= 0f)
{
dead();
}
}
}
It's attached to the enemy, the enemy gets instantiated and gets a random number of live
Then there is the shootscript, where I want to change the int value, to let it be uncluttered:
public int bulletdmg;
void Start()
{
GetComponent<health>().bulletdamage = bulletdmg;
}
I get the error:
"NullReferenceException: Object reference not set to an instance of an object"
What to do?