android


Unity 2D - Instantiated prefab inconsistent position across devices?


I have made a 2d android racing game using unity 5. i was testing the game on my phone(Asus Zenfone 5 with lollipop) it worked perfectly also tested the game on other phone(Samsung Galaxy Duos with jellybean) worked Perfectly as well.
BUT when i tested it on Samsung Galaxy s5 the instantiated prefabs have a different Y coordinate value(they start being instantiated from the middle of the screen & they were suppose to instantiate from the top corner).
Vector3 carPos = new Vector3 (Random.Range(-0.95f, 1.0f), transform.position.y, transform.position.z);
carNo = Random.Range(0, 4);
Instantiate (cars[carNo], carPos, transform.rotation);
For a 2D game, you use Vector2s to save coordinates instead of a Vector3s. I believe that this problem occurs, because the screen size of the different devices are different. To solve this problem try using versatile measurements like Screen.width or Screen.height when positioning. For example, if you were trying to instantiate a car in the top right corner of the screen you would use
Vector2 carPos = new Vector2(Screen.width, Screen.height);
Instantiate (cars[carNo], carPos, transform.rotation);
You can implement the random x coordinates of the cars with Random.Range() with respect to the Screen.width.

Related Links

sending Post on facebook wall [closed]
Draw a rectangular over an image by code
How to implement debug logs in Android's JNI
Android - How to get the image using Intent data
Image OCR Android
Android: Identify that phone is connected to a guest network over wifi
Can't stop a service started with alarmManager
ProgressBar not updating correctly after return to Activity
Android child activity and orientation lock
Android - Proper way of using AsyncTasks?
In-App Payments for Android Amazon AppStore
Obfuscation error - NoSuchMethodError: android.view.LayoutInflater.inflate
Result from Native Call always Returns 1717986916
Android: RuntimeException with PreferenceScreen and Custom Attributes from inside a Library Project
SQLite - Select and Integer type
Can we give the integer value of the secondary camera in setVideoSource?

Categories

HOME
phantom-dsl
localization
saml-2.0
requirements
google-apps
tvos
gluon-mobile
crystal-lang
qpython
rtf
tput
speech-synthesis
radgridview
libusb
coin3d
job-scheduling
symfony-console
mapstruct
shortest-path
nim
enterprise-miner
windows-xp
direct3d11
custom-post-type
progress-bar
firebase-analytics
userdefaults
recurring-events
python-2.6
simplecv
card.io
android-maps-extensions
vue-chartjs
joomla2.5
wurfl
signals-slots
stringtokenizer
claims
lpsolve
file-sharing
strftime
lampp
proget
tinymce-3
bluez
spring-data-couchbase
edit
cmp
google-photos
preprocessor
google-cloud-console
burrows-wheeler-transform
mapinfo
expectations
tooleap
appscale
mediametadataretriever
angular-ui-typeahead
nss
data-protection
turbo-prolog
yajsw
fink
beanstalk
halcon
opl
wiredep
jdi
branch-and-bound
botan
ansi
user-permissions
fits
broadband
mmwormhole
grouping-sets
rapidsvn
memset
terminate
isqlquery
windows-phone-8-sdk
beaker-testing
video-codecs
superscrollorama
server-administration
sqlclr
booksleeve
web-notifications
ilasm
landscape-portrait
matlab-load
fsevents
mysql-error-1205
photolibrary
luajava
object-database
skype4java
windows-identity
linfu-dynamicproxy
unmanagedresources

Resources

Encrypt Message