c# - Syntax : 'x' is a 'variable' but is used as a 'method' -
public gameobject explosionprefab; void oncollisionenter(collision otherobj) { gameobject explosionobject = instantiate(explosionprefab, otherobj.transform.position, quaternion.identity) gameobject; explosionobject(explosionobject, 5f); <-- line giving error destroy(otherobj.gameobject); } }
i in confusion because haven't been doing scripting long , wondering if show me right way this, small test game on unity. wondering how fixed , don't make mistake in future.
in general
a method declaration:
void x() { // }
a call method:
x();
a declaration of varialble:
int x = 0;
use of variable:
x = 7; //write y = x; //read , assing variable
your code
you declared variable:
gameobject explosionobject = instantiate(explosionprefab, otherobj.transform.position, quaternion.identity) gameobject;
but use like method:
explosionobject(explosionobject, 5f); <-- line giving error
you may missed method name, in case want call method of gameobject instance? example:
explosionobject.mymethod(explosionobject, 5f);
or may used same name instance , method, try change name of instance of gameobject:
gameobject game = instantiate(explosionprefab, otherobj.transform.position, quaternion.identity) gameobject; explosionobject(game, 5f);
Comments
Post a Comment