unity2d

Collision callback function not called

瘦欲@ 提交于 2019-12-29 01:29:34
问题 i am bloody beginner with Unity and i am currently working on a 2D Brawler. The movement works perfectly but my colliders don't do what they should... I want to detect if two GameObjects Collide (Spear and Player2) and if the collide Player2s healthPoints should decrease by Spears AttackDamage. The names of the GameObjects are also their tags. The Spears Prefab has following configuration: SpriteRendered(Material Sprites-Default), BoxCollider2D(Material None Physics Material 2D, IsTrigger(not

Wait for a coroutine to finish before moving on with the function C# Unity

依然范特西╮ 提交于 2019-12-28 06:59:11
问题 I was working on making a unit move through a grid in Unity2d. I got the movement to work without problems. I would want the function MovePlayer to wait until the coroutine is finished before moving on, so the program will wait until the player has finished the movement before issuing more orders. Here is my code: public class Player : MonoBehaviour { public Vector3 position; private Vector3 targetPosition; private float speed; void Awake () { speed = 2.0f; position = gameObject.transform

How To Crop Captured Image? --C#

Deadly 提交于 2019-12-24 07:09:08
问题 Is it possible to crop the captured image based on the shape that I want? I'm using raw image + web cam texture to activate the camera and save the image. And I'm using UI Image overlay method as a mask to cover the unwanted parts. I will be attaching the picture to the char model in the latter part. Sorry, I am new to unity. Grateful for your help! Below is what I have in my code: // start cam void Start () { devices = WebCamTexture.devices; background = GetComponent<RawImage> (); devCam =

Detect if colors are matched

断了今生、忘了曾经 提交于 2019-12-24 03:27:10
问题 I am trying to detect if colors are matched (2x2) in Unity2D, but it doesn't fully work. I have 16 tiles with 4 different colors. I am detecting if the colors are matched with a script, which is attached to each collider which collides with 4 tiles around it. In front of each colider is a button, which rotates the 4 tiles around that button (collider) to the right. The scripts of the colliders have a list called childTiles. The list contains the 4 tiles around that collider, to detect if

Error with WaitHandle and Thread.Sleep

梦想与她 提交于 2019-12-13 08:46:27
问题 I looked around on here for a way to make my script wait a few seconds and found this article which people recommended. I took some of this code and used it in my game to make it wait but it doesn't act as I want it to. I placed it between two Debug.Log lines but it waits for the designated time and then logs both things at once instead of waiting after the first has triggered. static void Waiter(){ waitHandle.WaitOne (); } Debug.Log (choice); new Thread (Waiter).Start (); Thread.Sleep (5000)

GameObject's Following a Leader / Centipede Issue

情到浓时终转凉″ 提交于 2019-12-12 14:33:59
问题 I am having difficulty chaining together some GameObjects to "Follow the leader". This is what I am trying to accomplish: Where there is a "head" object and it pulls the body objects with it. Like a snake or centipede. However, this is what is happening: They all kinda follow the head and but they seem to move as a whole. Can anyone see what I am doing wrong? Here is my Centipede Object that the others classes inherit from. I started to tinker with the idea of just making the CentipedeObject

2D Character, left animation is not being accessed

安稳与你 提交于 2019-12-12 04:39:11
问题 I have issue in Unity with my 2D characters animation. I simply made the animation of it walking right and left. I set things up in the animator, and for some reason the right animation is being accessed, but not the left whenever I press "A". This is the code part of animation of my PlayerController script: anim.SetFloat("mSpeed", Mathf.Abs(rb.velocity.x)); Animator Setup 回答1: Figured out what to do instead of using left animation, I just used the Sprite Render to Flip.X when the "A" key is

04 Unity2D

不羁岁月 提交于 2019-12-02 10:42:23
Unity2D系统是Unity引擎进行2D制作时使用的 Sprite精灵: 在Unity2D制作中将图片称作精灵(Sprite),为了提高游戏效率,降低对GPU的损耗,通常将一类的图片拼接成一张大图来使用 关于精灵的创建 1.选中多个图片,将TextureType设为 Sprite(2D and UI),所有的图片设一个统一的packing tag ,apply之后使用SpritePacker创建精灵 2.一张已经拼接好的图片,将TextureType设为 Sprite(2D and UI),SpriteMode设为Multiple ,apply之后点击SpriteEditor之后,slice切割,根据图片和需求选择不同的切割方式. 2D物理引擎 各种碰撞器都有对应的2D碰撞器,物体也有2D的刚体组件(Rigidbody2D) 2D的碰撞检测和触发检测的回调方法与3D的差不多,不过是在方法名字和参数类型的后面加2D 模拟愤怒小鸟(小球打砖块) 砖块添加Box Collider 2D,小球添加Circle Collider 2D void OnMouseDown () { //按下鼠标的时候记录小球的起点 begin = Input.mousePosition; } void OnMouseUp () { //松开的时候记录下小球的的终点 end = Input

Load all scenes during splash screen

痞子三分冷 提交于 2019-11-30 22:56:07
I have a multiple scenes in my mobile 2D unity game, I want to load all my scenes in splash screen, so that the scene passing would be smooth. How can I do this ? If I do this, do I need to change "Application.LoadScene()" method, and what method can I use ? do I need to change "Application.LoadScene()" method, and what method can I use ? You need to use SceneManager.LoadSceneAsync if you don't want this to block Unity while loading so many scenes. By using SceneManager.LoadSceneAsync , you will be able to show the loading status. I want to load all my scenes in splash screen Create a scene

Load all scenes during splash screen

大城市里の小女人 提交于 2019-11-30 18:29:16
问题 I have a multiple scenes in my mobile 2D unity game, I want to load all my scenes in splash screen, so that the scene passing would be smooth. How can I do this ? If I do this, do I need to change "Application.LoadScene()" method, and what method can I use ? 回答1: do I need to change "Application.LoadScene()" method, and what method can I use ? You need to use SceneManager.LoadSceneAsync if you don't want this to block Unity while loading so many scenes. By using SceneManager.LoadSceneAsync ,