|
Alright, I am going to post the code for this script, but since i am working on it, it is VERY messy and slightly confusing. I usually clean scripts up once they start to work.
Like i said it is very messy. The idea here is to fire a cannon when the fire button is clicked. When it fires, it will spawn a cannon ball, and the camera will follow the cannon ball, and watch it hit stuff. Well i got the whole spawning thingy to work (really messy as the transform for it is messed up because the modeler screwed with them). Now the problem is the array that i want to use to track the movement of the cannon ball. The way to cameraScrolling script is set up (it is the same one used in the 2d Gameplay tutorial made by Unity) is it takes a array, and sets it as the target. So i need to set the newly created cannon ball, to be added to the array, so the script can access it, but it will not work. I have tried many ways but none seem to work. Please help me out, as i am completely lost with arrays.
(comments are locked)
|
|
There are a few different kinds of array available in Unity. The ones defined with square brackets [] are not resizable, so you can't use Add or Remove, or any functions which change the size. What you probably want is a "Javascript Array", which does have these functions. For a more detailed description of the various arrays and when you might want to choose each, see this Unity Wiki Article: Upvoted - is there a Duck fanclub that I can join?
Oct 01 '10 at 03:24 AM
Marowi
@Marowi probably not much to do with what you wanted (and I don't even like sports that much either) but here's a "ducks fanclub": http://www.goducks.com/ :P
Dec 12 '10 at 09:00 PM
Cawas
(comments are locked)
|
|
There is no upper limit to the number of cannon balls you can spawn, so you should use a dynamic array, such as ArrayList or a Javascript Array
You would need to initialize the array
And to add your cannonball to it, just use Push
However, if you wish to use fixed native array, there's a couple of things to remember.
So the code might look like: couple of notes : indexing starts at zero for all kinds of array in Unity's Javascript and C# (not just fixed size arrays). Also, your code above seems to miss adding an item into position zero!
May 14 '10 at 08:21 AM
duck ♦♦
Thanks for the catch; should add to array first then increment >.<
May 14 '10 at 04:46 PM
Extrakun
(comments are locked)
|
