Expression denotes a 'type'

“Expression denotes a ‘type’ where a ‘variable’ ‘value’ or ‘method group’ was expected”

It seems that there are many of these posts but they all seem rather specific to the code, or rather I haven’t seen a good explanation of it but anyway; Could someone please find out whats wrong with my code and if possible provide a link to or an explanation of this error.

  GameObject Arrow = Instantiate(projectile, bow.transform.position, bow.transform.rotation ) as GameObject;
			Arrow.GetComponent(ArrowFlight).currentTarget = target;

Many thanks.

First of all if you code in C# you must do this :

 Arrow.GetComponent<ArrowFlight>().currentTarget = target;

Cause it’s cleaner.

Second :

  ArrowFlight ArrowFlightObj = (ArrowFlight) Arrow.GetComponent<ArrowFlight>();
  ArrowFlightObj.currentTarget = target;

Or something like that :wink:

“Expression denotes a ‘type’ where a ‘variable’ ‘value’ or ‘method group’ was expected”

An “Expression” is, basically, anything that can be interpreted as a group. (x+1) is an expression, Arrow is an expression, Instantiate() is an expression.

One of your expressions is a type (meaning, when the compiler sees it, it gets an actual class back), but it should be a variable, a value, or a method group (function call).

Just noticed - it looks like you’re mixing JS and C# syntax. C# declares variables as “Type name = (Type)InitializationFunction()”; JS declares them as “var name : Type = InitializationFunction() as Type”. Pick the format that fits your file type :stuck_out_tongue:

// this is valid but not in this case V

You can’t name variables the same thing as classes. That’s a minor reason why everyone will recommend that you use CamelCase for classes and functions, and camelCase for variable names.

Change your variable name from Arrow to something that isn’t a class name.