- Home /
Question by
peginet · Oct 15, 2014 at 07:23 AM ·
errorupdateoncollisionenterparameters
Script Error (EnemyHeal): Update() can not take parameters.
Here is a script
#pragma strict
var enemyHeal : int = -5;
var item : Transform;
var enemy : Transform;
function Update(col : Collider) {
if(col.gameObject.tag == "Bullet")
{
enemyHeal -= 30;
}
if(enemyHeal <= 0)
{
var position : Vector3 = Vector3(Random.Range(-10.0, 10.0), 0, Random.Range(-10.0, 10.0));
Instantiate(item, enemy.transform.position + Vector3(0,20,0) + position, Quaternion.identity);
Destroy(this.gameObject, 2);
}
}
When "Bullet" hits "Enemy" i got this error "Script Error (EnemyHeal): Update() can not take parameters."
Comment
Best Answer
Answer by HarshadK · Oct 15, 2014 at 07:25 AM
And the error is true. Update method does not take any parameter. What you are looking for is the OnTriggerEnter method to which you pass a Collider as argument.
So your code becomes:
#pragma strict
var enemyHeal : int = -5;
var item : Transform;
var enemy : Transform;
function OnTriggerEnter(col : Collider) {
if(col.gameObject.tag == "Bullet")
{
enemyHeal -= 30;
}
if(enemyHeal <= 0)
{
var position : Vector3 = Vector3(Random.Range(-10.0, 10.0), 0, Random.Range(-10.0, 10.0));
Instantiate(item, enemy.transform.position + Vector3(0,20,0) + position, Quaternion.identity);
Destroy(this.gameObject, 2);
}
}
And the error is true.
Amen to that. It always shocks me how many of the questions on this site can be dealt with by following the instructions in the error message.
Looking at the right spot is always the first key towards successful debugging. At least that is what I believe. :-)
Your answer
![](https://koobas.hobune.stream/wayback/20220613165127im_/https://answers.unity.com/themes/thub/images/avi.jpg)