I apparently suck at coding C#, I have absolutely no idea where to even start with fixing this error. I have an idea of what it is, but I don’t know what variables I need to put in the middle for it to work. Here is my script:
using UnityEngine;
using System.Collections;
public class AfterInstantiation : MonoBehaviour {
private GameObject control;
private GameManager manager;
private bool overlapping = true;
private GameObject overlapper;
private Bounds bounds1;
private Collider[] hitColliders;
private Bounds bounds2;
void Start(){
overlapper = GameObject.FindGameObjectWithTag("ground");
bounds1 = gameObject.renderer.bounds;
hitColliders = Physics.OverlapSphere(transform.position, 2);
bounds2 = hitColliders;
if (!bounds1.Intersects (bounds2)){
Debug.Log ("Destroying " + gameObject);
Destroy (gameObject);
}
else {
MarkAsInstantiated ();
}
}
void MarkAsInstantiated(){
control = GameObject.FindGameObjectWithTag ("Manager");
manager = control.GetComponent <GameManager> ();
GameManager.dungeonsExisting += 1;
}
}
I am trying to get the object to delete itself if it spawns on top of another object, so I want to draw an OverlapSphere to check if the object is hitting another object, and if it is, I want to delete it. So here is the error I be getting on line 17:
Assets/Scripts/Level Generators/Corridors and Rooms/AfterInstantiation.cs(17,17): error CS0029: Cannot implicitly convert type UnityEngine.Collider[]' to
UnityEngine.Bounds’
I have no idea how to even start trying to fix this error, though it’s probably something obvious. Any ideas? Help is much appreciated.
Edit:
If anybody could tell me how to convert hitColliders into all the gameObjects that it hits, I could also go from there.