Hey everyone! Back again to plague you with more errors[:P] I’m trying to convert the EnemyAI script from the Coppers in Lerpz Escapes, but I’ve run into a coupla’ errors;
Assets/Scripts/NewEnemyScript.cs(69,17): error CS0127: `NewEnemyScript.RotateTowardsPosition(UnityEngine.Vector3, float)': A return keyword must not be followed by any expression when method returns void
And
Assets/Scripts/NewEnemyScript.cs(69,17): error CS0029: Cannot implicitly convert type float' to
void’
Basically, they all trace back to this line in the code;
void RotateTowardsPosition(Vector3 targetPos, float rotateSpeed)//doesn't like this...
{
Vector3 relative = transform.InverseTransformPoint(targetPos);
float angle = Mathf.Atan2 (relative.x, relative.z) * Mathf.Rad2Deg;
float maxRotation = rotateSpeed * Time.deltaTime;
float clampedAngle = Mathf.Clamp(angle, -maxRotation, maxRotation);
transform.Rotate(0, clampedAngle, 0);
return angle;//or this...
}
That’s in Csharp, and this is the original code;
function RotateTowardsPosition (targetPos : Vector3, rotateSpeed : float) : float
{
// Compute relative point and get the angle towards it
var relative = transform.InverseTransformPoint(targetPos);
var angle = Mathf.Atan2 (relative.x, relative.z) * Mathf.Rad2Deg;
// Clamp it with the max rotation speed
var maxRotation = rotateSpeed * Time.deltaTime;
var clampedAngle = Mathf.Clamp(angle, -maxRotation, maxRotation);
// Rotate
transform.Rotate(0, clampedAngle, 0);
// Return the current angle
return angle;
}
If anyone could help me out there I’de be much obliged.