- Home /
Call Function with Collision-parameter
Hello, I have a list of functions that are called in the update-function:
function Update(){
carPhysicsUpdate();
checkInput();
damage(col);
}
and the damage function looks like this:
function damage(col : Collision){
...
}
But when I want to start the game the script can not find the col-parameter. Is it with collision-parameters not the same way as normal variables (int, string, bool...)?
Thanks in advance.
Answer by DoTA_KAMIKADzE · May 01, 2015 at 05:20 PM
It is exactly the same as with all the other variables.
Do you have a variable of type Collision named col outside of your Update function?(or inside your Update function, I've asked because there is none in your code example)
Also it is not a good approach to name parameter the same way as your variable in script if you have both in same script (it still should work anyway).
P.S. Also if you have your col variable, have you assigned something to it? Check it with your Debug.Log:
Debug.Log(col);//either before you call your function or on the first line of your function.
Also if you can have null value in your col variable then it would be a good approach to have if condition inside your function:
if (col != null)//do your code
Your answer
Follow this Question
Related Questions
Callable object ? 0 Answers
v.important : Choose one from functions to execute !! 1 Answer
How to make a game object of a certain class? 1 Answer
Calling a from another script c# 2 Answers
Cancelling Destroy(gameObject, time); 3 Answers