unity3d-2dtools

Positioning UI elements with Anchor Presets via code

瘦欲@ 提交于 2020-08-24 07:07:10
问题 When we position UI elements in Unity, we fix the position from Anchor Presets, so that it's position is placed correctly on the canvas. We select top, middle, bottom, stretch and the blue color dot. How can I do the same thing if I create UI element in the code in C#? I make Texture2D textureWhite = new Texture2D(1, 1); textureWhite.SetPixel(0, 0, Color.white); textureWhite.Apply(); How can I fix as top left corner together with blue color dot? 回答1: The anchors(min,max) values and the pivot

Camera following Rigidbody jitter every few seconds with background objects

坚强是说给别人听的谎言 提交于 2020-02-25 06:58:39
问题 Camera following Rigidbody2D jitter every few seconds with background (non rigidbody) objects (Obstacles). The FPS in profiler is fine it is near to 100. also Interpolate is also fine. Using Unity 2017.4.12 (LTS) GIF GIF Video here Camera Follow Script public class CameraFollow : MonoBehaviour { public float followRange = 0.5f; public float cameraZ; public Transform Player; public Vector3 newPos; void Start () { cameraZ = transform.position.z; } void FixedUpdate() { newPos = new Vector3

How to play 3D animation on a 2D canvas in Unity

痞子三分冷 提交于 2020-01-21 09:11:07
问题 I like to play animation on a Canvas. I made a canvas as shown in the following image. I like to play a golfer animation on the green color canvas. Is it possible? I have animation model as shown in the second figure. I like to play that golfer animation on the canvas. How can I do that? I drag and put under canvas as child object, it doesn't work. 回答1: As I explained in my comment, I would do as follow : Put your object in a specific layer (called MyLayer for the sake of the example) Set the

Collision on X axis means 0 movement in Y axis

三世轮回 提交于 2020-01-06 02:54:25
问题 I'm developing a platformer in Unity using the 2D engine. I have my player character which has a BoxCollider2D and a RigidBody, and a number of 'walls' which have BoxColliders. Now, I copied the script for moving the player from another project and made some changes. The part which has to do with movement is as follows: public void FixedUpdate() { physVel = Vector2.zero; // move left if(Input.GetKey(KeyCode.LeftArrow)) { physVel.x = -runVel; } // move right if(Input.GetKey(KeyCode.RightArrow)

Collision on X axis means 0 movement in Y axis

為{幸葍}努か 提交于 2020-01-06 02:54:05
问题 I'm developing a platformer in Unity using the 2D engine. I have my player character which has a BoxCollider2D and a RigidBody, and a number of 'walls' which have BoxColliders. Now, I copied the script for moving the player from another project and made some changes. The part which has to do with movement is as follows: public void FixedUpdate() { physVel = Vector2.zero; // move left if(Input.GetKey(KeyCode.LeftArrow)) { physVel.x = -runVel; } // move right if(Input.GetKey(KeyCode.RightArrow)

Universal screen resolutions in Unity for Android

余生颓废 提交于 2019-12-25 02:59:32
问题 I am new to Android development. I sent my app for testing on a couple of devices and a couple were fine, but a couple had the game half way off the screen. In the game scene everything is fine so what could be causing this in some devices? I am using one main camera set to orthographic and it is a simple 2d game. I guess one of my mistakes was not using the canvas properly and so I will make improvements, but why would this be like this in the game scene where I cannot use a canvas? Do I

Make texture2D readable in runtime/script Unity3D [duplicate]

妖精的绣舞 提交于 2019-12-22 17:36:19
问题 This question already has an answer here : How to make Texture2D Readable via script (1 answer) Closed 2 years ago . I have a plugin that allows me to access pictures from an Android phones gallery. This gives me a texture of the Texture2D type. I then want to edit it using the GetPixels function, but it is not set to readable by default. How would I make the texture readable so I can use GetPixels on it? Basically I am allowing the user to select a picture from the phone and then crop it. In

Why do my Unity Buttons need multiple taps to finally work?

淺唱寂寞╮ 提交于 2019-12-22 07:48:19
问题 As the title suggests, I have a screen with two canvases. Both literally a copy of each other, but simply having a different layout for my Portrait and Landscape orientations. As and when the orientation changes, I disable to appropriate Gameobject containing the Canvas. Now, I've never had any problems with the other buttons from the previous canvas open, but I've got this problem where my active canvas needs multiple taps on the same button to finally WORK. Should I be doing something

Unity3D Sprite … but single sided?

强颜欢笑 提交于 2019-12-21 17:52:46
问题 Unity's excellent new Sprite s (to wit, Unity's excellent new sprites), among other worthy advantages, are in fact double-sided. In a 2D or 3D use case, you can flip the little bastards around and still see them from behind - they are rendered from both sides. I also love the unlit shader used on them (ie, Sprite-Default, not Sprite-Diffuse). However I have need for an old-fashioned single-sided Sprite . Fortunately, you can freely download the source of the excellent shader used by Unity ...

Getting png crush error while creating ipa from unity editor in Xcode 7

↘锁芯ラ 提交于 2019-12-20 04:16:02
问题 I am getting png crush error while creating ipa from unity editor. I did a sample game and want to run it on iPhone. So i opened build settings from unity editor and chooses iOS platform like below mentioned image. After selected iOS platform, It opens in Xcode 7 and i connected iPhone device. While Building this game am getting this error. I know why this png crush error (In Xcode we have more than one image with same name) occurred. Am using one plugin library for android os. On that