Home > other >  The unity of the multiple Prefab objects bound the same script
The unity of the multiple Prefab objects bound the same script

Time:09-19

Made a unity 3 d game of tetris, seven square is a Prefab, each tetris is composed of four cube, they are bound the same script, the script for detecting the whereabouts of squares and legitimacy, and other functions, but the runtime after landing the first square, the second square and can normal landing back, try to print the information found, there to traverse the transform in the legitimacy of testing all of the child, the child of the first square will also be included; Trying to destroy the first square (after) it disappeared from the scene, the square can normal whereabouts, but this is not the tetris game, is there any way to keep the front of the square in the case of disappearing in the scene to solve the problem,

CodePudding user response:

The code Chou Chou,

CodePudding user response:

Isn't written traversal traversal all scenarios, should start from the roots of precast body traversal, each square a prefabricated body
A better approach is to actually inside of child nodes directly into an array structure, direct deposit on precast body
Instead of each time to traverse the child nodes

CodePudding user response:

Prefabricated body is a a to generate and control the precast body,
After fall below the control script is useless
Direct delete,

CodePudding user response:

Multiple objects bound to the same script, the script runs after is a different object.
So you only need to write a field ids in the script, cloned objects, this ID assigned different values, respectively, and then you own distinction is which according to the ID, so that to avoid the synchronization (can be done only one operation, other uncontrolled with script)
This is a train of thought, can see understand?

CodePudding user response:

Prefab once created is relatively independent, can separate

CodePudding user response:

Using a 2 d array, to describe the space distribution of cube, if is null, is empty, if not null, points to a square object,
Write a Cube script, use made of prefabricated body to the Cube, the script has left/right/detection, mainly detect whether placed next to the other objects in 2 d array,
Write a Group, a script, which is used to describe a variety of shapes, shape formed by the Cube precast body, matrix or a 2 d array is used to describe the shape, the script has the function of the rotation of the Group,

This approach is easy to make a collision detection/destroyed,,

CodePudding user response:

Use a this just like

CodePudding user response:

Use a this just like

CodePudding user response:

Use a this just like
  • Related