x


Unity iPhone and Unity Desktop Scripting Differences

I was developing a game in Unity Basic but recently purchased Unity iPhone Basic to release the game on the iPad. Everything seems to look ok, except I am having a few weird script errors.

One: Operator '-' cannot be used with a left hand side of type 'Object' and a right hand side of type 'Object'.

var balls = GameObject.FindGameObjectsWithTag("Ball");

    var zs = new Array();
    var ys = new Array();


    for(var i = 0; i < balls.length; i++){
        zs[i] = balls[i].transform.position.z;
        ys[i] = balls[i].transform.position.y;
    }


    ys.Sort();
    zs.Sort();


    var zdiff = zs[zs.length-1] - zs[0]; // ERRORS HAPPEN HERE
    var ydiff = ys[ys.length-1] - ys[0]; // ERRORS HAPPEN HERE

What is wrong with the code? It works perfectly in both Windows and Mac Unity Basic... Are there any huge differences that I should know of between Unity iPhone and Desktop when scripting?

more ▼

asked Jul 28 '10 at 04:58 AM

Andrew 5 gravatar image

Andrew 5
5 3 3 6

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

The main difference is that you can't use dynamic typing on Unity iPhone. (Basically all Javascript has an invisible "#pragma strict" applied to it.) In this particular case you have to cast the array as the appropriate type.

more ▼

answered Jul 28 '10 at 05:13 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

Thank you for your help!

Jul 28 '10 at 05:16 AM Andrew 5
(comments are locked)
10|3000 characters needed characters left

there is not much difference, specially if you enable .net 2.0 features then most things will be the same but you should write a really fast code to be able to run it on an iphone. however ipad is much faster. take a look at this

the only feature that is not supported is dynamic typing so your array should be casted to the original type and then anything will be correct and you are good to go.

more ▼

answered Jul 28 '10 at 05:14 AM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5081
x3738
x3460
x2000

asked: Jul 28 '10 at 04:58 AM

Seen: 2126 times

Last Updated: Jul 28 '10 at 04:58 AM