So I have a sphere game object that I want to instantiate. I’ve been able to get it so that when you click on a sphere or its clone that another instantiation doesn’t occur. However, when I click right next to the sphere, another sphere is created that meshes with the other. Here’s my code and see if you can try to help me:
using UnityEngine;
using System.Collections;
public class Instantiate : MonoBehaviour {
Ray ray;
RaycastHit hit;
public GameObject Sphere;
public int count;
public Transform teleport1;
public Transform teleport2;
public GameObject Cube;
void OnTriggerEnter(Collider other) //This is where I've tried to stop the meshing, but to no avail.
{
if(other.gameObject.CompareTag ("Sphere"))
{
other.gameObject.Destroy;
}
}
void Update ()
{
if(Input.GetButtonDown("Fire1"))
{
Cube.transform.position = teleport1.position;
}
if(Input.GetButtonDown("Fire2"))
{
Cube.transform.position = teleport2.position;
}
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit))
{
if (Input.GetMouseButtonDown (0))
{
if(hit.transform.name != "Sphere" && hit.transform.name != "Sphere(Clone)")
{
Instantiate (Sphere, hit.point + new Vector3(0, 0.5f, 0), Quaternion.identity);
count = count + 1;
}
}
}
}
}