2D Toolkit Forum
2D Toolkit => Support => Topic started by: mygamingproject on August 24, 2014, 11:31:01 am
-
I think I am probably making this difficult for myself but I simply want to spawn a prefab in a position that is always within the camera view.
The issue I think I am having is I'm confusing pixels with Screen points in my positioning so some appear and some others don't but nonetheless can't work it out.
Any assistance would be appreciated.
-
What camera settings are you using?
-
Its a tk2dCamera
With the following settings:
http://imgur.com/L5QpgpO
http://imgur.com/KJxMxLh
http://imgur.com/5SlH4lU
Setup to handle iDevice resolutions
-
camera.transform.position will put something at the bottom left of the camera.
you can then use tk2dCamera.ScreenExtents to work out the extents of the complete visible area of the camera.
-
Yep that did it thanks
My camera origin was actually marked as center so I came up with the crude code as follows which works
Vector3 cameraPosition = camera.transform.position;
Rect extents = camera.ScreenExtents;
float screenX = Random.Range(cameraPosition.x - (extents.width * 0.5f), cameraPosition.x + (extents.width * 0.5f));
blockPrefab.Spawn(new Vector3(screenX, 26.0f, 0.0f), transform.rotation);