Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Jul 22, 2014 at 03:31 PM by JusticeAShearing for the following reason:

I have no need of this knowledge any more.

avatar image
0
Question by JusticeAShearing · Jul 17, 2014 at 04:31 PM · arraynameinstancesrecognitionseparate

Can an Instance Array Recognize Separately Named Instances?

I have a script that makes an array of instances, but I need it to find separate instances. I doubt that they will ever become gameObjects. However, I have a separate question on that if you have a script that spawns gameObjects. Please respond if you do!

Raycasting may suggest a solution, and this question is really planning for the future. However, if you have an answer, please don't wait to post it. I am consistently working on this, and have spent half of my development time on this separate-instance-destroying issue.

Just a recap, I need it to recognize separate instances, perhaps by name, preferably totally separate. I would also love it if one could translate this into Java Script.

Here's the script:

 /*
     Script to blow up terrain engine trees
     (C)2009 by Tom Vogt <tom@lemuria.org>
     
     Released under the Creative Commons "Share Alike" license, see http://creativecommons.org/licenses/by-sa/3.0/
     DeadReplace must contain a collider and a rigidbody, or it'll fall through the terrain. :-)
 */
 
 
 using UnityEngine;
 using System.Collections;
 
 public class Tree_Blaster : MonoBehaviour {
 
     public float BlastRange = 30.0f;
     public float BlastForce = 30000.0f;
     public GameObject DeadReplace;
     public GameObject Explosion;
     
     void Explode() {
         Instantiate(Explosion, transform.position, Quaternion.identity);
         //Get the terrain data of the active terrain
         TerrainData terrain = Terrain.activeTerrain.terrainData;
         
         ArrayList instances = new ArrayList();
         
         foreach (TreeInstance tree in terrain.treeInstances) {
             float distance = Vector3.Distance(Vector3.Scale(tree.position, terrain.size) + Terrain.activeTerrain.transform.position, transform.position);
             if (distance<BlastRange) {
                 // the tree is in range - destroy it
                 GameObject dead = Instantiate(DeadReplace, Vector3.Scale(tree.position, terrain.size) + Terrain.activeTerrain.transform.position, Quaternion.identity) as GameObject;
                 dead.rigidbody.maxAngularVelocity = 1;
                 dead.rigidbody.AddExplosionForce(BlastForce, transform.position, BlastRange*5, 0.0f);
             } else {
                 // tree is out of range - keep it
                 instances.Add(tree);
                 
             }
         }
         terrain.treeInstances = (TreeInstance[])instances.ToArray(typeof(TreeInstance));
 
     }
 
     void Update() {
         if (Input.GetButtonDown("Fire1")) {
             Explode();
         }
     }
     
 }

Any help is appreciated, provided that you actually know or have thought about it before posting. If you need more information, please comment.

Comment
Add comment · Show 2
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 Huacanacha · Jul 17, 2014 at 04:44 PM 0
Share

What do you mean by 'recognise'? What is the exact behaviour you are trying to achieve? What do you mean by instance... do you mean any object, a Unity GameObject created using Instantiate etc?

avatar image JusticeAShearing · Jul 19, 2014 at 01:50 PM 0
Share

An instance is, for example, a tree painted onto a terrain. It's there in the 3D universe, but not an actual gameObject. They are not instantiated, they are not gameObjects.

Recognition of individual terrain trees is the ability to walk up to one and perform an action that affects it without affecting another.

I exactly want to destroy one tree without destroying any others. This can be done in any way, I don't $$anonymous$$d, but preferably by chopping them (timed destroy).

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

22 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 avatar image avatar image avatar image

Related Questions

NullReferenceException with a text array 1 Answer

trying to instatiate prefab multiple times in array 0 Answers

Find Closest Object by Name 0 Answers

IndexOutOfRangeExeption - Array index is out of range 2 Answers

Storing a variable and it's name 3 Answers


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