Hello, I’m sorry to come back to the charge, but I do not understand the principle for instantiation and anim that fair. I read the post indicated but even with Google translation it does not change anything. I searched the net, I do not find better. It was possible to have a simple and detailed explanation. thanks, count on your understanding
Sorry, I do not really understand your question.
Hello everyone, I have a little problem.
- I’m laying down prefabs
- I select 1 by its index
- I play 1 of his animation
that’s where I have a problem the original position of the prefab is (-5,6, -5)
and at the moment of animation, he positions himself (0,0,0)
as an indication in the animation only the vector Y passes from Y = 6 to Y = 10 rotation of Z = 180 ° with Y = 15 then y = 6
bonjour à tous, j’ai un petit problème.
- j’instancie des préfabs
- j’en sélectionne 1 par son index
3 ) je joue 1 des ses animation
c’est là que j’ai un problème la position originale du préfab est (-5,6,-5)
et au moment de l’animation il se positionne tout seul (0,0,0)
a titre indicatif dans l’animation seul le vecteur Y passe de Y = 6 à Y = 10 rotation de Z = 180° avec Y = 15 puis y = 6
Okay, from what I’ve read, I believe you have to setup your animations so they were as local positions.
In other words, you can use an empty game object as a parent, and place your instantiated prefab(s) in there (using 1 or more empty parents, I suppose). Set them up so their positions are appropriate in that local space and try that.
for the moment I instantiate 4X4 pieces or 16 pieces double faces.
Pieces [ ] is the stokage table (index) and an empty Game object Spawn serves as a parent.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Jeux : MonoBehaviour
{
public int Stage; // 4,6,8,10
public Animation anim;
public GameObject Prefab;
public GameObject Spawn;
public GameObject[] Pieces;
private int[,] Regarde;
private int[,] Terrain;
void Awake ()
{
}
// Use this for initialization
void Start ()
{
Stage = 4;
Reset ();
}
// retournement
public void RetPio (int Ind)
{
Debug.Log ("Base" + Ind);
//convertion de l'index en matrice X/Y
int y = (Ind / Stage);
int x = Ind - (y * Stage);
if (y != 0) {
y++;
}
if (x != 0) {
x++;
}
// regarde dans les 8 directions N/NE/E/SE/S/SO/O/NO
for (int i = 0; i < 8; i++) {
int xx = x + Regarde [i, 0];
int yy = y + Regarde [i, 1];
if (Ind != 0) {
xx--;
yy--;
}
if (xx >= 0 && xx <= Stage) {
Debug.Log ("xx :" + xx);
if (yy >= 0 && yy <= Stage) {
Debug.Log ("yy :" + yy);
int noIn = (yy * Stage + xx);
Debug.Log ("ind :" + noIn);
anim = Pieces [noIn].GetComponent<Animation> ();
if (Terrain [xx, yy] == 1) {
Terrain [xx, yy] = 2;
anim.Play ("sautNB");
} else {
Terrain [xx, yy] = 1;
}
}
}
}
}
public void Reset ()
{
Regarde = new int[8, 2];
Terrain = new int[Stage, Stage];
Pieces = new GameObject[Stage * Stage];
int comun = ((Stage / 2) * 10) - 5;
int posDeX = 0 - comun;
int posDeY = comun;
//remplissage table
int k = 0;
for (int i = 0; i < Stage; i++) {
int y = posDeY - (i * 10);
for (int j = 0; j < Stage; j++) {
int x = posDeX + (j * 10);
Pieces [k] = Instantiate (Prefab, new Vector3 (x, 6, y), Quaternion.identity)as GameObject;
Pieces [k].transform.parent = Spawn.transform;
k++;
Terrain [j, i] = 1;
}
}
//table Regard
Regarde = new int[8, 2]
{
{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1}
};
}
}
[ICODE][/ICODE]