Bullet Sharp collision not working in SharpDX - c#

Okay so im trying to implement physics into my Game, tho everything works it looks like there is no collision on the objects :(
Here is a video of whats going on: https://streamable.com/w5h4vd
My Code is pretty simple:
I have this function for setting the scene:
settingScene = true;
foreach (GameObject go in scene.GameObjects)
{
var extent = go.renderer.Mesh.Extent;
Debug.WriteLine("Extent Min: " + extent.Min);
Debug.WriteLine("Extent Max: " + extent.Max);
Debug.WriteLine("Extent Center: " + extent.Center);
CollisionShape shape;
List<Vector3> vertices = new List<Vector3>();
List<int> indices = new List<int>();
indices.AddRange((from v in go.renderer.Mesh.IndexBuffers[0]
select (int)v));
vertices.AddRange((from v in go.renderer.Mesh.VertexBuffers[0]
select v.Position - extent.Center));
Debug.WriteLine("Vertex Count: " + vertices.Count);
Debug.WriteLine("Index Count: " + indices.Count);
shape = new BvhTriangleMeshShape(new TriangleIndexVertexArray(indices.ToArray(), vertices.ToArray()), true);
Debug.WriteLine("Shape Convex: " + shape.IsConvex);
go.renderer.World = Matrix.Identity;
var body = new RigidBody(
new RigidBodyConstructionInfo(
go.Weight,
new SMotionState(go),
shape, shape.CalculateLocalInertia(go.Weight)));
Debug.WriteLine("Body Shape Scaling: " + body.CollisionShape.LocalScaling);
if (body.IsStaticObject)
{
body.Restitution = go.Restitution;
body.Friction = go.Friction;
}
go.body = body;
world.AddRigidBody(body);
}
settingScene = false;
The scene class is only a list of GameObjects, which store Position rotation and scale.
I use this for stepping the sim:
if (settingScene) return;
if ((float)simTime.Elapsed.TotalSeconds < time)
{
time = 0;
timeStep = 0;
}
timeStep = ((float)simTime.Elapsed.TotalSeconds - time);
time = (float)simTime.Elapsed.TotalSeconds;
world.StepSimulation(timeStep, 7);
and i use this for initialisation:
simTime.Start();
time = 0f;
timeStep = 0f;
world = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, conf);
world.Gravity = new Vector3(0f, -9.81f, 0f);
All Variables:
static DynamicsWorld world;
static CollisionConfiguration conf = new DefaultCollisionConfiguration();
static ConstraintSolver solver = new SequentialImpulseConstraintSolver();
static Dispatcher dispatcher = new CollisionDispatcher(conf);
static BroadphaseInterface broadphase = new DbvtBroadphase();
static Stopwatch simTime = new Stopwatch();
static float time, timeStep;
static bool settingScene = false;
What am i doing wrong?
Why do the cube not have collision?
I got a step further: it detects collision when doing rig.CheckCollideWith but it doesnt do anything else with collision
I have tried:
Printing all the values from the body and GameObject to see if there is any problem
Hard coding the values
Any help will be greatly appreciated!

Related

Why would frames drop considerably the longer a Unity Game runs?

I am using Unity 2020.3.4f1 to create a 2D game for mobile.
I created a map builder for the game.
When I hit play, it makes a bunch of 'maps' that are saved as json files. The longer the game plays seems to result in extremely slow frame rates (200fps -> 2 fps) based on the stats menu while the game is running.
The strange thing is if I go to the "Scene" tab and left click on a sprite the fps instantly jumps back up again.
Screenshots
The problem seems related to taking screenshots within Unity.
The big bulge happens & only resets when I un-pause the game.
Questions
Why would the frame rates drop considerably over time the longer the game is running?
Why would the frame rate jump back up after selecting a sprite in the "Scene" tab?
What happens in Unity when selecting a sprite in the "Scene" tab? Is there a garbage collection method?
Script:
private void Awake()
{
myCamera = gameObject.GetComponent<Camera>();
instance = this;
width = 500;
height = 500;
}
private void OnPostRender()
{
if(takeScreenShotOnNextFrame)
{
takeScreenShotOnNextFrame = false;
RenderTexture renderTexture = myCamera.targetTexture;
Texture2D renderResult = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false);
Rect rect = new Rect(0, 0, renderTexture.width, renderTexture.height);
renderResult.ReadPixels(rect, 0, 0);
float myValue = 0;
float totalPixels = renderResult.width * renderResult.height;
for (int i = 0; i < renderResult.width; i++)
{
for (int j = 0; j < renderResult.height; j++)
{
Color myColor = renderResult.GetPixel(i, j);
myValue += myColor.r;
//Debug.Log("Pixel (" + i + "," + j + "): " + myColor.r);
}
}
occlusion = ((myValue / totalPixels) * 100);
byte[] byteArray = renderResult.EncodeToPNG();
System.IO.File.WriteAllBytes(Application.dataPath + "/Resources/ScreenShots/CameraScreenshot.png", byteArray);
// Cleanup
RenderTexture.ReleaseTemporary(renderTexture);
myCamera.targetTexture = null;
renderResult = null;
}
}
private void TakeScreenshot(int screenWidth, int screenHeight)
{
width = screenWidth;
height = screenHeight;
if(myCamera.targetTexture != null)
{
RenderTexture.ReleaseTemporary(myCamera.targetTexture);
//Debug.Log("Camera target texture null: " + myCamera.targetTexture == null);
}
myCamera.targetTexture = RenderTexture.GetTemporary(width, height, 16);
takeScreenShotOnNextFrame = true;
}
public static void TakeScreenshot_Static(int screenWidth, int screenHeight)
{
instance.TakeScreenshot(screenWidth, screenHeight);
}
}

Create mesh from an Object with Spatial Awareness Mesh Observer MHL2

I'm new here and also quite new at C#/Unity2019.4.14f with VS2019, MRTK V2.5.3, and Microsoft Hololens 2 programming. I would like to ask you for advice on a problem that I have not been able to solve for weeks. First of all, I would like to quickly explain what kind of problem it is. My task is to track an object that is in an examination cube with the Spatial Mesh and to represent its shape as well as possible.Explanation screen for the task description
The calculations of where the examination cube is located in space work without any problems. But for some reason, I cannot query the Spatial Awareness Mesh Observer. Anyway, no meshes seem to be present although they are visible.
Since I am at a complete loss and no one I have asked so far has been able to help me, I am publishing my code for this function below. Please bear with me, as I am still a beginner in writing code.
public void ReadAndDrawMesh(){
//Provide a list of the cube coordinates
Vector3[] CubeCoordinateList = new Vector3[24];
//Convert Local to World Coordinates
var localToWorld = transform.localToWorldMatrix;
Vector3 cubeWorldPos = Cube.transform.position; // Reading out the centre position
Vector3[] cubeVertices = Cube.GetComponent<MeshFilter>().mesh.vertices; //World coordinates?
List<Vector3> cubeWorldVertices = new List<Vector3>();
for (int i = 0; i <= (cubeVertices.Length) - 1; i++)
{
CubeCoordinateList[i] = localToWorld.MultiplyPoint3x4(cubeVertices[i]);
}
//CubeVerticies from Vector A[0] to E[4]
float normalX1 = CubeCoordinateList[4].x - CubeCoordinateList[0].x;
float normalY1 = CubeCoordinateList[4].y - CubeCoordinateList[0].y;
float normalZ1 = CubeCoordinateList[4].z - CubeCoordinateList[0].z;
float amount1 = Mathf.Sqrt((normalX1 * normalX1) + (normalY1 * normalY1) + (normalZ1 * normalZ1));
//Create a new vector
Vector3 direction1 = new Vector3(normalX1, normalY1, normalZ1);
direction1 = direction1 / amount1;
//CubeVerticies from Vector A[0] to B[2]
float normalX2 = CubeCoordinateList[2].x - CubeCoordinateList[0].x;
float normalY2 = CubeCoordinateList[2].y - CubeCoordinateList[0].y;
float normalZ2 = CubeCoordinateList[2].z - CubeCoordinateList[0].z;
float amount2 = Mathf.Sqrt((normalX2 * normalX2) + (normalY2 * normalY2) + (normalZ2 * normalZ2));
//Create a new vector
Vector3 direction2 = new Vector3(normalX2, normalY2, normalZ2);
direction2 = direction2 / amount2;
//CubeVerticies from Vector A[0] to D[3]
float normalX3 = CubeCoordinateList[3].x - CubeCoordinateList[0].x;
float normalY3 = CubeCoordinateList[3].y - CubeCoordinateList[0].y;
float normalZ3 = CubeCoordinateList[3].z - CubeCoordinateList[0].z;
float amount3 = Mathf.Sqrt((normalX3 * normalX3) + (normalY3 * normalY3) + (normalZ3 * normalZ3));
//Create a new vector
Vector3 direction3 = new Vector3(normalX3, normalY3, normalZ3);
direction3 = direction3 / amount3;
//From MRTK 2.5.3
// Use CoreServices to quickly get access to the IMixedRealitySpatialAwarenessSystem
var spatialAwarenessService = CoreServices.SpatialAwarenessSystem;
// Cast to the IMixedRealityDataProviderAccess to get access to the data providers
var dataProviderAccess = spatialAwarenessService as IMixedRealityDataProviderAccess;
var meshObserverName = "SpatialAwarenessMeshObserverProfile";
var MeshObserver = dataProviderAccess.GetDataProvider<IMixedRealitySpatialAwarenessMeshObserver>(meshObserverName);
foreach (SpatialAwarenessMeshObject meshObject in MeshObserver.Meshes.Values)
{
Vector3[] meshObjectarray = meshObject.Filter.mesh.vertices;
//Reading the Spatial Mesh of the room
foreach (Vector3 verticiesCoordinaten in meshObjectarray)
{
//List for the mesh coordinates that come out of the scalar product calculation
Vector3[] MeshPositionList = new Vector3[meshObjectarray.Length]; ;
//Determining Direction between verticiesCoordinates of MeshObject with Centre of Cube
var dir_vectorMesh = verticiesCoordinaten - cubeWorldPos;
//Calculating the scalar product of the coordinates
var result1 = Mathf.Abs(Vector3.Dot(dir_vectorMesh, direction1)) * 2;
var result2 = Mathf.Abs(Vector3.Dot(dir_vectorMesh, direction2)) * 2;
var result3 = Mathf.Abs(Vector3.Dot(dir_vectorMesh, direction3)) * 2;
// If scalar product Negative, then write it in the list
if (result1 > amount1 && result2 > amount2 && result3 > amount3)
{
MeshPositionList[meshObjectarray.Length] = verticiesCoordinaten;
}
//Creating a new visible mesh from the points in the list
Mesh mesh = new Mesh();
mesh.vertices = MeshPositionList;
mesh.Optimize();
Graphics.DrawMeshNow(mesh, Vector3.zero, Quaternion.identity);
mesh.RecalculateNormals();
}
}
}
I hope that one of you can help me and I look forward to any constructive answers. Thank you to everyone who reads this post and perhaps responds.
Thank You.

Unity Text Ui looks small on android device

I'm new to unity and I've developing a simple 2d game.
at scoreboard scene i've managed to save scores and display them on a scrollview. when i run it in unity it works fine but when i build and run in my android phone the scrollview looks a bit bigger and text ui (added by script) look very small.
Here is the code to display scores in content game object in scrollview :
void Start () {
if (PlayerPrefs.HasKey (0 + "HScore")) {
float y = -30;
for (int i = 0; i < 10; i++) {
if (PlayerPrefs.GetInt (i + "HScore") == 0) {
break;
}
GameObject textobj = new GameObject (i + "HScoreName", typeof(RectTransform));
GameObject textobj2 = new GameObject (i + "HScore", typeof(RectTransform));
Text name = textobj.AddComponent<Text> ();
Text score = textobj2.AddComponent<Text> ();
GameObject lineObj = new GameObject ("Line", typeof(RectTransform));
Image l = lineObj.AddComponent<Image> ();
l.color = Color.white;
lineObj.transform.localScale = new Vector3 (500, 0.01f, 1);
name.text = "#" + (i + 1) + "- " + PlayerPrefs.GetString (i + "HScoreName");
score.text = PlayerPrefs.GetInt (i + "HScore").ToString ();
name.color = Color.white;
score.color = Color.white;
name.alignment = TextAnchor.MiddleLeft;
score.alignment = TextAnchor.MiddleLeft;
name.horizontalOverflow = HorizontalWrapMode.Overflow;
name.font = Resources.GetBuiltinResource<Font> ("Arial.ttf");
score.font = Resources.GetBuiltinResource<Font> ("Arial.ttf");
name.fontSize = 15;
score.fontSize = 15;
score.fontStyle = FontStyle.Bold;
textobj.transform.position = content.transform.position + new Vector3 (70, y, 0);
textobj.transform.SetParent (content.transform);
textobj2.transform.position = content.transform.position + new Vector3 (180, y, 0);
textobj2.transform.SetParent (content.transform);
lineObj.transform.position = content.transform.position + new Vector3 (60, y - 25, 0);
lineObj.transform.SetParent (content.transform);
y = y - 50;
}
}
}
is there anything missing in this script to keep text fit with screen?
You are using flat numbers, what you need s a percentage of Screen.width and Screen.height
For example if you are running in a phone with resolution 150x150 for example, if you want it in position 5, 5 you write this
transform.position = (5 / 100) * 150, it will set your object at 5 PERCENT from the bottom left edge.
There is a component - Canvas Scaler on the Canvas. Try to to change UI Scale Mode - Scale with Screen Size - it must be on the Canvas. And also you can play with Math value
Try to change UI Scale Mode - Scale with Screen Size - it must be on the Canvas.

How To Make 3D Script Work With 2D (Unity C#)

So I have a script that shoots an arrow when you click and drag, kinda like Angry Birds.
I want it to work with the 2D RigidBody and 2D collider but when I change the rigidbody.AddForce to rigidbody2D.AddForce, It doesn't work.
How can I fix this to work for 2D?
I also want the arrow to rotate in 2D space either up or down depending on where mouse is pulled back. When I try the mouse look script, it rotates it in the z axis (I think) and distorts the arrow. Any easy solution to fix this??
Thanks guys. I'm new to game making and I've been trying to figure this stuff out for like the last 10 hours. I need some pros to help!
Thanks!!!
Heres my script
using UnityEngine;
using System.Collections;
public class DragShotMover2 : MonoBehaviour {
public float maxDragLength = 2; // this is the base magnitude and the maximum length of the line drawn in the user interface
public float maxMultiplier = 5; // multiply the line length by this to allow for higher force values to be represented by shorter lines
public Vector3 dragPlaneNormal = Vector3.up; // a vector describing the orientation of the drag plan relative to world-space but centered on the target
public SnapDir snapDirection = SnapDir.away; // force is applied either toward or away from the mouse on release
public ForceMode forceTypeToApply = ForceMode.VelocityChange;
public bool overrideVelocity = true; // cancel the existing velocity before applying the new force
public bool pauseOnDrag = true; // causes the simulation to pause when the object is clicked and unpause when released
public Color noForceColor = Color.yellow; // color of the visualization helpers at force 0
public Color maxForceColor = Color.red; // color of the visualization helpers at maximum force
public enum SnapDir {toward, away}
private Vector3 forceVector;
private float magPercent = 0;
private bool mouseDragging = false;
private Vector3 mousePos3D;
private float dragDistance;
private Plane dragPlane;
private Ray mouseRay;
private GameObject dragZone;
private string shaderString = "Transparent/Diffuse";
private Material dzMat;
void Start (){
Color currentColor = noForceColor;
dzMat = new Material(Shader.Find(shaderString));
// create the dragzone visual helper
dragZone = new GameObject("dragZone_" + gameObject.name);
dragZone.AddComponent<MeshFilter>().mesh = MakeDiscMeshBrute(maxDragLength/4);
//dragZone.GetComponent.MeshFilter.
dragZone.AddComponent<MeshRenderer>();
dragZone.renderer.enabled = false;
dragZone.name = "dragZone_" + gameObject.name;
dragZone.transform.localScale = new Vector3(maxDragLength*2, 0.025f, maxDragLength*2);
dragZone.renderer.material = dzMat;
dragZone.renderer.material.color = currentColor * new Color(1,1,1,0.2f);
// create the dragplane
dragPlane = new Plane(dragPlaneNormal, transform.position);
// orient the drag plane
if (dragPlaneNormal != Vector3.zero) {
dragZone.transform.rotation = Quaternion.LookRotation(dragPlaneNormal) * new Quaternion(1, 0, 0, 1);
}
else Debug.LogError("Drag plane normal cannot be equal to Vector3.zero.");
//update the position of the dragzone
dragZone.transform.position = transform.position;
}
void OnMouseDown (){
mouseDragging = true;
if (pauseOnDrag) {
// pause the simulation
Time.timeScale = 0;
}
// update the dragplane
dragPlane = new Plane(dragPlaneNormal, transform.position);
// orient the drag plane
if (dragPlaneNormal != Vector3.zero) {
dragZone.transform.rotation = Quaternion.LookRotation(dragPlaneNormal) * new Quaternion(1, 0, 0, 1);
}
else Debug.LogError("Drag plane normal cannot be equal to Vector3.zero.");
//update the position of the dragzone
dragZone.transform.position = transform.position;
dragZone.renderer.enabled = true;
}
void OnMouseDrag (){
Color currentColor = noForceColor;
// update the plane if the target object has left it
if (dragPlane.GetDistanceToPoint(transform.position) != 0) {
// update dragplane by constructing a new one -- I should check this with a profiler
dragPlane = new Plane(dragPlaneNormal, transform.position);
}
// create a ray from the camera, through the mouse position in 3D space
mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
// if mouseRay intersects with dragPlane
float intersectDist = 0.0f;
if (dragPlane.Raycast(mouseRay, out intersectDist)) {
// update the world space point for the mouse position on the dragPlane
mousePos3D = mouseRay.GetPoint(intersectDist);
// calculate the distance between the 3d mouse position and the object position
dragDistance = Mathf.Clamp((mousePos3D - transform.position).magnitude, 0, maxDragLength);
// calculate the force vector
if (dragDistance*maxMultiplier < 1) dragDistance = 0; // this is to allow for a "no move" buffer close to the object
forceVector = mousePos3D - transform.position;
forceVector.Normalize();
forceVector *= dragDistance * maxMultiplier;
// update color the color
// calculate the percentage value of current force magnitude out of maximum
magPercent = (dragDistance * maxMultiplier) / (maxDragLength * maxMultiplier);
// choose color based on how close magPercent is to either 0 or max
currentColor = noForceColor * (1-magPercent) + maxForceColor * magPercent;
// dragzone color
dragZone.renderer.material.color = currentColor * new Color(1,1,1,0.2f);
// draw the line
Debug.DrawRay(transform.position, forceVector / maxMultiplier, currentColor);
}
//update the position of the dragzone
dragZone.transform.position = transform.position;
}
void OnMouseUp (){
mouseDragging = false;
if (overrideVelocity) {
// cancel existing velocity
rigidbody.AddForce(-rigidbody.velocity, ForceMode.VelocityChange);
}
// add new force
int snapD = 1;
if (snapDirection == SnapDir.away) snapD = -1; // if snapdirection is "away" set the force to apply in the opposite direction
rigidbody.AddForce(snapD * forceVector, forceTypeToApply);
// cleanup
dragZone.renderer.enabled = false;
if (pauseOnDrag) {
// un-pause the simulation
Time.timeScale = 1;
}
}
void OnGUI (){
if (mouseDragging) {
Vector2 guiMouseCoord = GUIUtility.ScreenToGUIPoint(Input.mousePosition);
GUI.Box ( new Rect(guiMouseCoord.x-30, Screen.height-guiMouseCoord.y+15, 100, 20), "force: "+Mathf.Round((forceVector).magnitude));
}
}
Mesh MakeDiscMeshBrute ( float r ){
Mesh discMesh;
Vector3[] dmVerts = new Vector3[18];
Vector3[] dmNorms = new Vector3[18];
Vector2[] dmUVs = new Vector2[18];
int[] dmTris = new int[48];
int i = 0;
discMesh = new Mesh();
dmVerts[0] = new Vector3(0,0,0);
dmVerts[1] = new Vector3(0,0,r);
dmVerts[2] = new Vector3(1,0,1).normalized * r; // find the vector at the correct distance the hacky-hillbilly way!
dmVerts[3] = new Vector3(r,0,0);
dmVerts[4] = new Vector3(1,0,-1).normalized * r;
dmVerts[5] = new Vector3(0,0,-r);
dmVerts[6] = new Vector3(-1,0,-1).normalized * r;
dmVerts[7] = new Vector3(-r,0,0);
dmVerts[8] = new Vector3(-1,0,1).normalized * r;
// set the other side to the same points
for (i = 0; i<dmVerts.Length/2; i++) {
dmVerts[dmVerts.Length/2 + i] = dmVerts[i];
}
for (i = 0; i<dmNorms.Length; i++) {
if (i<dmNorms.Length/2) dmNorms[i] = Vector3.up; // set side one to face up
else dmNorms[i] = -Vector3.up; // set side two to face down
}
dmUVs[0] = new Vector2(0,0);
dmUVs[1] = new Vector2(0,r);
dmUVs[2] = new Vector2(1,1).normalized * r;;
dmUVs[3] = new Vector2(r,0);
dmUVs[4] = new Vector2(1,-1).normalized * r;;
dmUVs[5] = new Vector2(0,-r);
dmUVs[6] = new Vector2(-1,-1).normalized * r;;
dmUVs[7] = new Vector2(-r,0);
dmUVs[8] = new Vector2(-1,1).normalized * r;;
// set the other side to the same points
for (i = 0; i<dmUVs.Length/2; i++) {
dmUVs[dmUVs.Length/2 + i] = dmUVs[i];
}
dmTris[0] = 0;
dmTris[1] = 1;
dmTris[2] = 2;
dmTris[3] = 0;
dmTris[4] = 2;
dmTris[5] = 3;
dmTris[6] = 0;
dmTris[7] = 3;
dmTris[8] = 4;
dmTris[9] = 0;
dmTris[10] = 4;
dmTris[11] = 5;
dmTris[12] = 0;
dmTris[13] = 5;
dmTris[14] = 6;
dmTris[15] = 0;
dmTris[16] = 6;
dmTris[17] = 7;
dmTris[18] = 0;
dmTris[19] = 7;
dmTris[20] = 8;
dmTris[21] = 0;
dmTris[22] = 8;
dmTris[23] = 1;
// side two
dmTris[24] = 9;
dmTris[25] = 11;
dmTris[26] = 10;
dmTris[27] = 9;
dmTris[28] = 12;
dmTris[29] = 11;
dmTris[30] = 9;
dmTris[31] = 13;
dmTris[32] = 12;
dmTris[33] = 9;
dmTris[34] = 14;
dmTris[35] = 13;
dmTris[36] = 9;
dmTris[37] = 15;
dmTris[38] = 14;
dmTris[39] = 9;
dmTris[40] = 16;
dmTris[41] = 15;
dmTris[42] = 9;
dmTris[43] = 17;
dmTris[44] = 16;
dmTris[45] = 9;
dmTris[46] = 10;
dmTris[47] = 17;
discMesh.vertices = dmVerts;
discMesh.uv = dmUVs;
discMesh.normals = dmNorms;
discMesh.triangles = dmTris;
return discMesh;
}
}
If you want to keep using the 3D Rigidbody, I'd suggest just using RigidbodyConstraints, so you can lock the z (or whatever) axis/rotation, and it will perform exactly the same as a 2D platformer.

Object transform.localScale not changing

I am adding some objects in the game but for same reason, the first object I add from a generic list do not change in localScale.
As you can see from the image below, the console displays that localScale is correct, but when you look at the gameview and inspector, the object has a Vector.zero localScale. What's weird is that all the other properties of the object is correct (i.e. object.name is correctly name 3, 7).
The objects after the first are all displayed correctly as well.
Update: If I don't use Queue<GameObject> tile = new Queue<GameObject>(), things work normally..
Here's the script:
public void animateGrid(List<int[]> matchTile, List<int[]> moveTile, List<int[]> appendTile){
animating = true;
Queue<GameObject> tile = new Queue<GameObject>();
Debug.Log ("MatchTile count: " + matchTile.Count);
Debug.Log ("AddTile count: " + appendTile.Count);
foreach(int[] i in matchTile){
tile.Enqueue(getGameObject(i[0], i[1]));
match (tile.Peek());
}
Debug.Log ("tile: " + tile.Count);
foreach(int[] j in appendTile){
int x1 = j[0], y1 = j[1],
x2 = j[2], y2 = j[3];
GameObject gameObj = tile.Dequeue();
Debug.Log ("tileNo");
append ( gameObj,
getCoordinateFromGrid(x2, y2),
x2, y2,
grid.filled[x1, y1]
);
}
...
}
private void match(GameObject tile){
Hashtable optional = new Hashtable();
optional.Add("ease", LeanTweenType.easeInBounce);
LeanTween.scale(tile, Vector3.zero, 0.05f, optional);
tile.SetActive(false);
}
private void append(GameObject tile, Vector3 position, int x, int y, int type){
float tileSize = 1f / 9f;
tile.renderer.material.color = getColor(type);
tile.tag = getType(type);
tile.name = x + "," + y;
tile.transform.parent = transform.FindChild("Filled").transform;
tile.transform.position = position;
tile.transform.localScale = new Vector3(tileSize, tileSize, 70f);
tile.SetActive(true);
Debug.Log ("added scale: " + tile.transform.localScale + " x:" + x + " y:" + y);
}
If I don't use Queue tile = new Queue(), things work normally. I think its a bug.

Categories