hello, i was wondering does someone can help me with the code i am using. i am using this code in a lot of places in my game:
the question is how to structure the code, so that i can make this a separate script and use it as a component? is there a way to use it like this:
ZoomComponent being the reference to the script where ZoomIn function is. sorting this out would be from great help!
asked Aug 06 '10 at 03:05 PM
You can use it like this:
So you can see that the "foo" variable is changed by the function. In your case, the "distance" variable would have to be changed from a float to a RefFloat, and you would access it by using "cam.distance.a" instead of "cam.distance".
answered Aug 06 '10 at 04:16 PM
Your ZoomIn function does not return a value, so you cannot do this.
What i suppose you are modifying is the camera position, so all you ZoomComponents need to be able to access the camera. I think the best way is to pass the world X,Y,Z values of your object (or better yet, the Transform of the GameObject you are zooming on) and then have the zoomComponent modify the the camera position. The reference to the camera should be made by creating a variable like this in the zoomComponent.
and then dragging the MainCamera onto this scriptComponent in the inspector. (You can also get it by camera = GameObject.Find("MainCamera").
Take care however, that there is not multiple zoomComponents affecting the single camera simoultainously. You can solve this by static variables.
I am quite new to Unity, so dont take me for a pro. Hope I can be of help.
answered Aug 06 '10 at 03:51 PM