- Home /
Question by
BurleyJ · Mar 10 at 09:56 AM ·
oncollisionenter
can GetComponent().fillAmount -= 0.1f; work with on collision enter?, GetComponent().fillAmount -= 0.1f; works fine if attached to getkeydown but not for oncollisionenter
can GetComponent().fillAmount -= 0.1f; work with on collision enter?,{ public Rigidbody Enemy; public Image healthBar; public void OnCollisionEnter(Collision collision) { GetComponent().fillAmount -= 0.1f;
}
}
Comment
Answer by Caeser_21 · Mar 10 at 12:17 PM
You have to use :
OnCollisionEnter(Collision collision)
{
collison.gameObject.transform.GetComponent(scriptName).fillAmount -= 0.1f; //'scriptName' should be replaced with the name of the desired script
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613054021im_/https://answers.unity.com/themes/thub/images/avi.jpg)