- Home /
Spawing a SpawnPoint with Raycast
Hello to everyone ı want to create gime like that
I am working a spawn Scripts but ı connot success . I can spawn a lot of object but if user select a item this item shouldnt be destroy. And The another object musnt be spawn same place. When user click 2. times the object destroys and onother objects can spawnthe that place.
// Erdem Köşk
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Spawner : MonoBehaviour
{
public GameObject point1;
public GameObject point2;
public bool statuspoint1 = true ;
public bool statuspoint2 = true;
public GameObject[] items;
public GameObject items1;
public GameObject items2;
public GameObject items3;
public float spawnTime;
public GUIText deneme;
public int number = 0;
// public float destroyTime;
void spawn()
{
if(statuspoint1){
int kind;
GameObject randomitem;
kind = Random.Range(0, items.Length - 1);
randomitem = items[kind];
GameObject clone = (GameObject)Instantiate(randomitem, point1.transform.position, point1.transform.rotation);
clone.transform.parent = point1.transform;
Destroy(clone, 4);
}
if (statuspoint2)
{
int kind;
GameObject randomitem;
kind = Random.Range(0, items.Length - 1);
randomitem = items[kind];
GameObject clone = (GameObject)Instantiate(randomitem, point2.transform.position, point2.transform.rotation);
clone.transform.parent =point2.transform;
Destroy(clone, 4);
}
}
// Use this for initialization
void Start()
{
items = new GameObject[4];
items[0] =items1;
items[1] = items2;
items[2] = items3;
InvokeRepeating("spawn", 1, spawnTime);
// enemySpawnPoints = GameObject.FindGameObjectsWithTag("Spawn");
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0)){
erdem();
}
}
public void erdem()
{
if (Input.touchCount > 0)
{
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint((Input.GetTouch(0).position)), Vector2.zero);
if (number % 2 == 0) {
if (hit.collider.name == "Point1")
{
statuspoint1 = false;
number++;
deneme.text = number.ToString();
}
}
else{
statuspoint1 = true;
number++;
}
}
}
}
Please help me..
Comment
Your answer
Follow this Question
Related Questions
Changing values of a script from another script not showing in game 1 Answer
why when i try to add my script to the "player" it says can not can not add script 1 Answer
Spawn or manual setup in Scene view (noobie question) 0 Answers
Random Spawning 1 Answer
Random cube length on instantiate... 1 Answer