Translating Java into C#?

i cant figure out how to translate this line of code from java to C#, im sure its something simple, just cant find it

function CalculateAimPosition(targetPos : Vector3)
{
var aimPoint = Vector3(targetPos.x + aimError, targetPos.y + aimError, targetPos.z + aimError);
desiredRotation = Quaternion.LookRotation(aimPoint);
}

Java and Javascript and Unityscript are all different things!

void CalculateAimPosition(Vector3 targetPos)
{
  var aimPoint = new Vector3(targetPos.x + aimError, targetPos.y + aimError, targetPos.z + aimError);
  desiredRotation = Quaternion.LookRotation(aimPoint);
}

Yes i know that they are two different things, too lazy i guess :smile:

May you translate one more thing for me please? i already did but i feel like its not accurate

for(theMuzzlePos in muzzlePositions)
{
Instantiate(myProjectile, theMuzzlePos.position, theMuzzlePos.rotation);
Instantiate(muzzleEffect, theMuzzlePos.position, theMuzzlePos.rotation);
}

Could you also please use the code tags to format your posts, really makes it easier to read. Just surround the code with [ code ] and [ /code ] … remove the spaces and your code will be nicely placed in a code block.
Without anything else to go on I don’t know if this will accomplish what you are going for or not:

foreach(var theMuzzlePos in muzzlePositions)
{
    GameObject.Instantiate(myProjectile, theMuzzlePos.position, theMuzzlePos.rotation);
    GameObject.Instantiate(muzzleEffect, theMuzzlePos.position, theMuzzlePos.rotation);
}

Sorry im new here, thanks for the heads up.

  foreach (theCannonPosition in cannonPosition)

this part requires an identifier and a type, the way i got around this was by using

 foreach (transform theCannonPosition in cannonPosition)

although im not really sure if thats a suitable translation

Sorry that I overlooked that, I edited the code I posted above. In C#, as long as you are in a local scope (i.e. inside a method, command block, etc), you can use implicit typing for things like this. So the following will behave the same for you:

// Here the type is explicit
foreach(Transform cannonPosition in cannonPostions){
    Debug.Log(cannonPosition.name);
}
//Here the type is implicit
foreach(var cannonPostion in cannonPositions){
    Debug.Log(cannonPosition.name);
}

Hope that helps a bit.

Thanks alot yes it did, thanks for your time :slight_smile: