I have this Tilesystem script you can but on yea small planes, think tower defece, and i cant get it too work i have tried some diffrent things but none of them have been succesfull here is the code.
The script is supose to spawn a tower when you left click the plane and should only spawn on that plane of the many diffrent prefab of the same plane.
using UnityEngine;
using System.Collections;
public class MyTileSystem : MonoBehaviour {
private bool On = true;
public GameObject ObjTower;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if(Input.GetMouseButton (0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast (ray, out hit))
{
MyTileSystem tile = hit.collider.GetComponent<MyTileSystem>();
if(tile != null)
{
tile.SpawnTower();
}
}
}
}
public void SpawnTower()
{
if(On)
{
On = false;
GameObject tower;
tower = Instantiate(ObjTower, transform.position, transform.rotation)as GameObject;
}
}
}