KimNA
November 7, 2013, 3:09pm
1
Hi guys!
I am currently developing my Unity- and C# skills, but i am trying to get some techniques from a javascript. I need to get your opinion about how to translate the following from Javascript to C#:
function CalculateAimPosition(Vector3 targetPos)
{
var aimPoint = Vector3(targetPos.x+aimError, targetPos.y+aimError, targetPos.z+aimError);
desiredRotation = Quaternion.LookRotation(aimPoint);
}
In the first code it is mostly how i save the Vector3 in aimPoint?
for(theMuzzlePos in muzzlePositions)
{
Instantiate(projectile, theMuzzlePos.position, theMuzzlePos.rotation);
Instantiate(muzzleEffect, theMuzzlePos.position, theMuzzlePos.rotation);
}
In the second code it is about how to write the foreach loop.
Thank you in advance
Marrrk
November 7, 2013, 3:27pm
2
Thats really simple:
void CalculateAimPosition(Vector3 targetPos)
{
var aimPoint = new Vector3(targetPos.x + aimError, targetPos.y + aimError, targetPos.z + aimError);
desiredRotation = Quaternion.LookRotation(aimPoint);
}
foreach (var theMuzzlePos in muzzlePositions)
{
Instantiate(projectile, theMuzzlePos.position, theMuzzlePos.rotation);
Instantiate(muzzleEffect, theMuzzlePos.position, theMuzzlePos.rotation);
}
KimNA
November 7, 2013, 3:50pm
3
Yes, I knew it was simple, i just need help sometimes. Thank you very much!
For people with the same simple problem in the future, does my code look like this now:
void CalculateAimPosition(Vector3 targetPosition)
{
Vector3 aimPoint = new Vector3(targetPosition.x + aimError, targetPosition.y + aimError, targetPosition.z + aimError);
desiredRotation = Quaternion.LookRotation(aimPoint);
}
foreach(Transform theMuzzlePos in muzzlePosition)
{
Instantiate(projectile, theMuzzlePos.position, theMuzzlePos.rotation);
Instantiate(muzzleEffect, theMuzzlePos.position, theMuzzlePos.rotation);
}