I want to start explaining that my english is not so good, so ill try me best. This is my problem:
im making a “Hole in wall” game and im trying to Spawn 3 walls to test my script, i used invokerepeating for this task and invoking coroutines to create my wall and move it . i dont know if im making myself clear, but i hope u guys can undertand the idea.
so… the problem is that after the first repeat my wall went to the original point and explode ( my wall was made by cubes order by a matrix), so when de second one comes,it explotes too. how can i fix this :/? this is my gameManager code. (C#)
using UnityEngine;
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
using System;
public class GameManager : MonoBehaviour {
public WallMaking Wall;
float timer = 0f;
// Use this for initialization
public void Spawner()
{
timer += Time.deltaTime;
//InvokeRepeating("Spawner()", 60f, 3f);
Debug.Log("SPAWNEA CTM!");
Debug.Log(timer);
StartCoroutine(Wall.WallMaker());
Vector3 Source = new Vector3(661.49f, 0.2f, 3.52f);
Vector3 Target = new Vector3(661.49f, 0.2f, -4.87f);
StartCoroutine(Wall.WallsMovement(Source, Target, 5f));
Debug.Log("hola");
Debug.Log(timer);
}
void Start() {
Debug.Log("A VER");
InvokeRepeating("Spawner", 1f, 5f);
Debug.Log("SE REPITE");
}
//float timer = 0f;
}
and this is my wallmaking code:
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
// C#
public class WallMaking : MonoBehaviour
{
int[,] mat ={
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},
};
int[,] mat2 ={
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,1,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},
};
int[,] mat3 ={
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,0,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},
};
int[,] matO;
List<int[,]> wallList = new List<int[,]>();
public IEnumerator WallMaker()
{
wallList.Add(mat);
wallList.Add(mat2);
wallList.Add(mat3);
System.Random rnd = new System.Random();
matO = wallList[rnd.Next(wallList.Count)];
float cubesizeX = 0;
float cubesizeY = 0;
for (int y = 0; y < 11; y++)
{
for (int x = 0; x < 11; x++)
{
if (matO[y, x] == 1)
{
GameObject Brick = GameObject.CreatePrimitive(PrimitiveType.Cube);
Brick.transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, transform.localScale.z);
Brick.AddComponent<Rigidbody>().useGravity = false;
Vector3 newPos = new Vector3((transform.position.x) + cubesizeX, (transform.position.y) + cubesizeY, transform.position.z);
Brick.transform.position = newPos;
Brick.transform.parent = GameObject.Find("MainWall").transform;
}
cubesizeX = cubesizeX + 0.3F;
}
cubesizeX = 0;
cubesizeY = cubesizeY + 0.3F;
}
Debug.Log("MAKING A WALL");
yield return null;
}
public IEnumerator WallsMovement(Vector3 source, Vector3 target, float overTime)
{
float startTime = Time.time;
while (Time.time < startTime + overTime)
{
Debug.Log("TIEMPO DE MOVERTE");
Debug.Log(startTime + overTime);
transform.position = Vector3.Lerp(source, target, (Time.time - startTime) / overTime);
yield return null;
}
transform.position = target;
}
//void Update() {
//KinectManager manager = KinectManager.Instance;
//uint playerID = manager != null ? manager.GetPlayer1ID() : 0;
//if (playerID > 0) {
// transform.Translate (-Vector3.forward* 2.0f * Time.deltaTime, Space.Self);
//}
// Debug.Log("MUEVETE");
//yield return null;
// }
}
hope u guys can helpme !