Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DoctorSauce · Jan 11, 2014 at 06:34 PM · colliderboundsoverlapsphere

Converting Collider to Bounds variable?

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.

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image helloiam · Jan 11, 2014 at 07:09 PM 0
Share

Try to replace the Collider[] with Bounds [] or at rule 17: bounds2 = (Bounds) hitcolliders. Try this litteraly.

avatar image DoctorSauce · Jan 11, 2014 at 07:19 PM 0
Share

Both of those things end up giving me the same error, sorry. Haha see why I'm so confused?

avatar image helloiam · Jan 11, 2014 at 07:23 PM 0
Share

You have an array of type Collider but which element are you initializing and Bounds isn't an array so therefor you can't convert it.

avatar image DoctorSauce · Jan 11, 2014 at 07:26 PM 0
Share

So I think, then, what I need to do is get the gameObjects of the colliders listed in hitColliders, and then test the bounds of each of those gameObjects. So in that case, how do I get the gameObjects from hitColliders?

avatar image helloiam · Jan 11, 2014 at 07:35 PM 0
Share

Just do like hitcolliders [0] = yourgameObject.collider ot yourgameobject.renderer.collider and for the bounds before yoy ask that yourgameObject.collider.bounds or the secondary way.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by helloiam · Jan 11, 2014 at 07:58 PM

You need to initialize your array in order to interact with bounds2 and then assign that to your bounds2 variable.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Aura/AOE Problem 2 Answers

Can I use a raycast to retrieve information from the collider? 2 Answers

3d Text how do you autofit to a fixed space 0 Answers

collider bounds intersect but than for a UI button element 0 Answers

Collider2d.bounds.Intersects not detecting intersection 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges