unity3d-2dtools

Collider2D vs Collision2D

核能气质少年 提交于 2019-12-08 04:50:19
问题 After doing some video tutorials on Youtube, I recognized that these two Classes look similar and repetitive. -Collision2D- This method called when an incoming collider makes contact with this object's collider (2D physics only) void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Enemy") coll.gameObject.SendMessage("ApplyDamage", 10); } -Collider2D- This method called when another collider makes contact with this object void OnTriggerEnter2D(Collider2D other) { Destroy

Why does Social.localUser.Authenticate lead to crash when there is no internet connection in Unity app?

三世轮回 提交于 2019-12-07 22:28:30
问题 With an internet connection Everything works flawlessly. There is no memory problem leading to crash. With no internet connection The app proceeds to the menu screen, where it eventually crashes because it is out of memory. I have concluded that the problem lies in the following line of code Social.localUser.Authenticate When I comment out the above line, the memory problem goes away when there is no internet connection. Here is my relevant code void Start () { Social.localUser.Authenticate

Make texture2D readable in runtime/script Unity3D [duplicate]

心已入冬 提交于 2019-12-06 15:24:32
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 the following example pic the picture would be cropped by the red rectangle. Which works if I make the

Why does Social.localUser.Authenticate lead to crash when there is no internet connection in Unity app?

佐手、 提交于 2019-12-06 10:19:56
With an internet connection Everything works flawlessly. There is no memory problem leading to crash. With no internet connection The app proceeds to the menu screen, where it eventually crashes because it is out of memory. I have concluded that the problem lies in the following line of code Social.localUser.Authenticate When I comment out the above line, the memory problem goes away when there is no internet connection. Here is my relevant code void Start () { Social.localUser.Authenticate(ProcessAuthentication); } public void ProcessAuthentication(bool success) { if(success) Debug.Log (

What is the most elegant way to let UI objects swallow touches in unity 5?

て烟熏妆下的殇ゞ 提交于 2019-12-05 16:53:08
My game uses unity 5 new UI system with canvas. The game itself can receive touches to shoot ammos via functions OnMouseDown() on several game objects with 2D colliders indicating touchable areas, and I can adjust the priorities of different touchable areas by changing the game objects' position.z. However with the UI added, any touches on UI elements (buttons, panels, etc.) will not only (if possible) trigger the UI elements, but they can also pass through UI elements and trigger the touchable areas. It's very weird when you press a button, not only the button is pressed, but also triggers

Unity3d Is there something like Mesh Collider for 2D objects?

只谈情不闲聊 提交于 2019-12-04 20:00:02
Im making simple 2D game, I designed the "way" the player going through in the game. If the player touches the wall the game is over, so I must detect collisions. At first I created the walls from sprites, but then I realized there is no 2D collider that suit himself to the shape of the sprit(it was to difficult to create the collider manually from a lot of smaller polygon and circle colliders), so I made all the walls that builds the "way" 3D objects(.dae files with z=0.001), and added them the mash collider which suits himself to the 3D object. I changed my player to be 3D as well so the

Unity3D Sprite … but single sided?

时光怂恿深爱的人放手 提交于 2019-12-04 10:01:29
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 ... confusingly, you can't just open it in the Editor, but see here and thence here . After considerable

How to load an image from URL with Unity?

浪子不回头ぞ 提交于 2019-11-28 01:13:59
问题 Please save me from going crazy. No matter how many times I google, I always end up with (usually deprecated) versions of the following code: IEnumerator setImage(string url) { Texture2D texture = profileImage.canvasRenderer.GetMaterial().mainTexture as Texture2D; WWW www = new WWW(url); yield return www; Debug.Log("Why on earh is this never called?"); www.LoadImageIntoTexture(texture); www.Dispose(); www = null; } I'm using Unity 5 not 4. The URL I'm trying to load exists. Please shine some

Camera.main is null when performing raycast

旧时模样 提交于 2019-11-26 08:35:30
问题 Code that generates an error: void Update() { if (Input.touchCount > 0) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position), Vector2.zero); if (hit && hit.collider != null && hit.collider.name == \"leftTapArea\") { hit.transform.name = \"Hit\"; } } } It says that something is wrong with this string: RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position), Vector2.zero); Error: NullReferenceException: Object