- Home /
"function DoRoll (Point, Axis, Angle, Duration)" Does Not Work on Android. Any reasons?
function DoRoll (Point,Axis,Angle,Duration) {
var tSteps = Mathf.Ceil(Duration * 30.0);
var tAngle = Angle / tSteps;
var pos : Vector3; // declare variable to fix the y position
// Rotate the cube by the point, axis and angle
for (var i = 1; i <= tSteps; i++)
{
transform.RotateAround (Point, Axis, tAngle);
yield WaitForSeconds(0.0033333);
}
// move the targetpoint to the center of the cube
transform.Find("targetpoint").position = transform.position;
// Make sure the y position is correct
pos = transform.position;
pos.y = startY;
transform.position = pos;
// Make sure the angles are snaping to 90 degrees.
var vec: Vector3 = transform.eulerAngles;
vec.x = Mathf.Round(vec.x / 90) * 90;
vec.y = Mathf.Round(vec.y / 90) * 90;
vec.z = Mathf.Round(vec.z / 90) * 90;
transform.eulerAngles = vec;
// The cube is stoped
ismoving = false;
}
Here is my script. I have no Idea why does it gives this error "Operator '*' cannot be used with a left hand side of type 'Object' and a right hand side of type 'float'." So I need your help. I tried to find answer in another questions like that, but unfortunately, i haven't.
The Error is in line " var tSteps = Mathf.Ceil(Duration * 30.0);
var tAngle = Angle / tSteps;
var pos : Vector3; // declare variable to fix the y position "
And The code is created by following instructions on "http://forum.unity3d.com/threads/how-to-move-camera-automatically.16190/"
And how to set "function DoRoll (Point,Axis,Angle,Duration) { " to "DoRoll(Vector3.zero, Vector3.up, 90.0, 1.0);"
The line number accompanying the error message would have been helpful, but I'd guess it's to do with var tSteps = $$anonymous$$athf.Ceil(Duration * 30.0);
- where do you declare Duration?
Is Duration a script? It's capitalised so I'd assume so. This would explain that error thrown by the line
var tSteps = $$anonymous$$athf.Ceil(Duration * 30.0);
in which Duration is an object and 30.0 is a float. Obviously, the Ceil function doesn't support arguments of that type.
Of course I'm guessing as you've included no line numbers for you errors.
And if you're building for mobile, you should really have #pragma strict
declared at the top of your script, which should have picked up on the fact that you've not explicitly declared the type of any of your vars. e.g.
var vec = transform.eulerAngles;
should be:
var vec : Vector3 = transform.eulerAngles;
Answer by Eric5h5 · Jun 22, 2014 at 07:46 PM
You must type all your variables.
// wrong:
function DoRoll (Point,Axis,Angle,Duration) {
// right:
function DoRoll (point : Vector3, axis : Vector3, angle : float, duration : float) {
Also, use lowercase for variable names. Uppercase is for classes and functions. I don't know if those are the correct types, by the way; that's just a quick assumption.