- Home /
Spawning Error..
Hello to everyone..
I have got a following scripts :
// Erdem Köşk
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Spawner : MonoBehaviour
{
private GameObject[] enemySpawnPoints;
List<Transform> iList = new List<Transform>();
public GameObject[] items;
public GameObject enemy;
public GameObject allied;
public GameObject bonus;
public float spawnTime;
// public float destroyTime;
bool duplicatePos;
bool isAdded;
void spawn()
{
int spawn1;
int kind;
GameObject randomEnemySpawn;
GameObject randomitem;
do
{
spawn1 = Random.Range(0, enemySpawnPoints.Length - 1);
kind = Random.Range(0, items.Length - 1);
randomEnemySpawn = enemySpawnPoints[spawn1];
randomitem = items[kind];
if (iList.Count == 0)
{
iList.Add(randomEnemySpawn.transform);
break;
}
else
{
foreach (Transform spawn in iList)
{
if (spawn.Equals(randomEnemySpawn.transform))
{
duplicatePos = true;
break;
}
}
if (!duplicatePos)
{
iList.Add(randomEnemySpawn.transform);
break;
}
duplicatePos = false;
}
} while (true);
GameObject clone = (GameObject)Instantiate(randomitem, randomEnemySpawn.transform.position, randomEnemySpawn.transform.rotation);
if (iList.Count >= 5)
{
iList.RemoveAt(0);
}
//iList.Remove(clone.transform);
// clone.transform.parent = parentObject.transform;
// Destroy(clone, destroyTime);
//isAdded = false;
duplicatePos = false;
}
// Use this for initialization
void Start()
{
items = new GameObject[4];
items[0] = enemy;
items[1] = allied;
items[2] = bonus;
InvokeRepeating("spawn", 1, spawnTime);
enemySpawnPoints = GameObject.FindGameObjectsWithTag("Spawn");
}
// Update is called once per frame
void Update()
{
}
}
This code provide spawining items. And items dont spawn duplicated. Hovewer ı want to send a raycast to spawned item. İt hits a collider this items dont be destroy. And this Script dont spawn any items to items position. How can change my code .. This code take a colliders. But my ıtems have got a colliders to so ı cannot reach this coordinates
Comment