- Home /
instantiate object at the edge of screen
hi guys...right at the end of project ive found a huge problem , and ...... ive build my project in 1366 * 768 and whole of my positions are in world space but in built project when resolution changes something change , and someobjects that were in borders of screen dissapear , so i used this code for my background ( this is a 2d game) to rescale it with different resolution
var NewObjectWidth : float ;
var OldObjectWidth : float ;
var NewObjectHeight : float ;
var OldObjectHeight : float ;
function Start ()
{
OldObjectWidth = this.transform.localScale.x ;
OldObjectHeight = this.transform.localScale.y ;
NewObjectWidth = OldObjectWidth * 764 / 1368 * Screen.width / Screen.height;
this.transform.localScale.x = NewObjectWidth ;
}
but because the camera aspect ratio changes in other resolutions such as 800 * 600 ,the problem of disappearing still remains , so i found a solution for this that make the objects base on resolution of cam instead of making them in world , so is there any way to instantiate objects base on the camera resolution , by the way ive used this code
var p : Vector3 = camera.ScreenToWorldPoint (Vector3 (100,100,-4));
Instantiate(CreateInstantiate ,p , transform.rotation) ;
but it doesnt work correctly ,the z parameter of p ..... and it should be connected to camera too..... sorry it was a long questions.....thanx alot
Answer by meat5000 · Oct 17, 2013 at 02:26 PM
The z position is in world units from the camera.
You have a negative value so points backwards, out of the screen. It points to your face, but thats not a valid gameobject or world point.
Also in
camera.ScreenToWorldPoint
the "camera." determines that the function is executed with respect to Camera "camera"
Your answer
Follow this Question
Related Questions
Reading Screen Dimension in Android Immersive Mode 1 Answer
Asset Variations for Different Mobile Screen Sizes 1 Answer
Max Resolution? Targeting 4320x5400 px... 1 Answer
Auto scaling GUI 3 Answers
2D Game. Screen, Camera and coordinates. 0 Answers