unity3d-2dtools

How to make custom Unity LayoutGroup expand to fit contents

偶尔善良 提交于 2019-12-13 04:27:44
问题 I am attempting to use a custom FlowLayoutGroup as described in the answers of this question ( also up on GitHub) in a situation where it needs to resize vertically to contain it's children. My setup looks like this: ScrollableRect Panel with VerticalLayoutGroup comp (content of parent scrollrect) that should resize vertically to fit children: Panel with FlowLayoutGroup that should resize vertically to fit children Panel with FlowLayoutGroup (2) also must resize... etc... I have added a

Unity 2D: PlayerPrefs Implementation for Highscore

本小妞迷上赌 提交于 2019-12-13 03:45:55
问题 I need some assistance implementing a HighScore that saves. Currently, I have a score, which starts from 500,000 and gets down 150 points per seconds. This works, although when I die it still goes on, which I need to fix. I have a second kmHighscore Text, and I want it to show the highscore. Right now it shows the exact score on which I died(for example 450,875), but when I restart the game I can't seem to make it be saved. I tried with PlayerPrefs, but I am not sure how to apply it in my

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

£可爱£侵袭症+ 提交于 2019-12-12 09:15: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

Back and forth movement using Rigidbody2D movePosition

[亡魂溺海] 提交于 2019-12-12 05:59:33
问题 I have two force fields I & II (Image here - https://i.stack.imgur.com/yXAhQ.png). They both have an attached script with a bool 'repel', which is toggled on MouseDown(). These force fields need to either attract or repel a spaceship directly in its path. The actual movement of the ship is done by raycasting right & down from the ship. These raycasts check the 'repel' bool of the force fields and the ship is then either moved away or towards the force fields. All gameObjects are Kinematic. I

Destroy a GameObject when it enters a trigger collider?

岁酱吖の 提交于 2019-12-12 04:17:18
问题 I am having trouble destroying a GameObject when it enters a GameObject with a BoxCollider2D that is set to be a trigger. I have a javascript script on the GameObject that reads as follows: #pragma strict function OnTriggerEnter (other : Collider) { Destroy(other.gameObject); } What I want the script to do is destroy any object that enters the trigger collider. My game is 2D, if that helps. Any help is appreciated! :) Also, what does #pragma strict do and why is it there? 回答1: I fixed the

How to detect if unity game is running on (web keyboard) or (mobile touch)

房东的猫 提交于 2019-12-11 08:20:03
问题 basically, I have a unity game supported by physical keyboards and touch screens in mobile devices. I already finished my movement script for physical keyboards, and now, I'm coding for touch screens. How can I achieve that detect feature? I was thinking something like that... private void HandleInput() { if (detect if physical keyboard here...) { if (Input.GetKey(KeyCode.RightArrow)) { _normalizedHorizontalSpeed = 1; } else if (Input.GetKey(KeyCode.LeftArrow)) { _normalizedHorizontalSpeed =

Apply Physics2D to 3D Game Objects - Unity3D

烂漫一生 提交于 2019-12-11 05:28:46
问题 Is it possible to use Physics 2D components(rigidbody2d,collider2d..etc) on 3d Game objects. I am planning develop 2 game with some of 3d model. Thanks! 回答1: It is not, however what you can do with rigidbody3d is lock the physics movement and rotation on it. For example, if you only ever wanted it to move along the x and y axis of your game, in the inspector just tick the freeze z movement box for the rigidbody component. 来源: https://stackoverflow.com/questions/27058919/apply-physics2d-to-3d

How to move 2D Object with WASD in Unity

爷,独闯天下 提交于 2019-12-11 04:26:19
问题 My code below only works for horizontal movement. Shouldn't the vertical movement be working too? I'm just starting out with basic 2D Unity programming: public class Player : MonoBehaviour { //These fields will be exposed to Unity so the dev can set the parameters there [SerializeField] private float speed = 1f; [SerializeField] private float upY; [SerializeField] private float downY; [SerializeField] private float leftX; [SerializeField] private float rightX; private Transform _transformY;

2D bouncing formula doesn't work properly

心已入冬 提交于 2019-12-11 02:33:46
问题 I am new to unity, and i am trying to create a bouncing ball, so i've did many researches about bouncing realted physics and i found a formula : Formula: -2*(V dot N)*N + V Where V is the velocity vector and N is the normal of the surface on which the ball will bounce Here is my script : using UnityEngine; using System.Collections; public class BallPhysics : MonoBehaviour { void Start () { rigidbody2D.velocity =new Vector2 (-1,-3); } // Update is called once per frame void Update () { } void

Unity Error: UnityEngine.Component' does not contain a definition for `velocity'

♀尐吖头ヾ 提交于 2019-12-10 22:03:30
问题 I am very new to C#, so forgive me if this is obvious. I am following the steps in this tutorial and have run into a problem on step six. The error it gives is this: The error it gives is this: UnityEngine.Component' does not contain a definition for `velocity' and no extension method `velocity' of type `UnityEngine.Component' could be found. Are you missing an assembly reference?' Here is the code: using UnityEngine; using System.Collections; public class RobotController : MonoBehaviour { /