I’m trying to convert from java to c#. I’m not getting errors, but when I convert they are basically not being assigned properly. What am I doing wrong?
//java
var arrow : GameObject = Instantiate (arrowPrefab, launchPosition.transform.position, launchPosition.transform.rotation);
//C#
//assigned but is never used
GameObject arrow = (GameObject)Instantiate(boltPrefab, tillerPosition.transform.position, tillerPosition.transform.rotation);
That’s actually javascript, not java. You should learn that now or it will get very confusing for both you and other people
JAVA != JAVASCRIPT
anyways, it’s kinda hard to get a picture… the c# is correct, the only thing I could think is that the variables that are helping instantiating are not working properly, or there is something wrong with them
Does the object get instantiated? what happens if it does that’s not normal?
You’ve explicitly declared a variable called ‘arrow’ of type GameObject. Unity’s Instantiate function returns a type of Object.
The UnityScript (UnityScript != JavaScript ) that you posted is essentially trying to implicitly cast an Object to a GameObject.
Rewrite it as… var arrow = Instantiate(...)
…and it will compile, but your arrow variable will now be of type Object.
Short story, to get it to work the way you want you need to explicitly cast the return type of the Instantiate function to a GameObject for the Unityscript code above to work, ie:
var arrow:GameObject = (GameObject)Instantiate(...)