|
For various reasons, I'm trying to keep a 3d object inside the screen, no matter how the player resize it, so I'm trying to make a code for it. But no matter what it doesn't seem to reach zero. Originally I was trying to just get the Screen.height as a float to compare with the transform.position.y, but I couldn't figure out how, and the coding got more complex. Normally, I'd just stick a invisible wall at the bottom of the screen, but that wouldn't fly this time.
(comments are locked)
|
NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) That error appears when I use this in JS: var camToObject: float = Mathf.Abs(mCamera.position.z - transform.position.z);
Oct 10 '11 at 05:25 PM
Persona
mCamera.transform.position.z
Oct 10 '11 at 08:05 PM
loopyllama
Still no change.
Oct 12 '11 at 03:51 AM
Persona
mCamera has to be set to an instance of a camera.
Oct 12 '11 at 04:20 AM
loopyllama
function Awake(){ //Set the main camera mCamera = Camera.main; }
Oct 12 '11 at 06:14 PM
Persona
(comments are locked)
|
|
The problem is that you are not checking against the bounds of the object. Each object in Unity has a bounds property that tells you exactly the space occupied by that object. You need to use the min and max values to compare them against the edges of the screen, and correct the position. Also, be sure to perform the checks in LateUpdate instead of Update, to ensure that all movement functions have finished. I have dealt with this issue before for a 2D game, so I can provide a component I made that restricts the movement to the screen.
(comments are locked)
|
