Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
3
Question by Jason 5 · Apr 22, 2010 at 06:30 AM · gameobjecttransformconvert

I'm trying to convert a Transform to a GameObject (?)

Hi. Thanks for reading this. Listen, I'm new to Unity and hope you pardon my possibly stupid question. Here's the breakdown:

I instantiate an instance of Drone. Then I push drone into a globalArray. When drone is pushed, it is a Transform object. Here's code:

var droneAmount:int = 10; // When a collision happens destroy ourselves // and spawn an explosion prefab instead

for(var i=0; i<droneAmount; i++){ var drone : Transform; var explosion : Transform; explosion = GameObject.Find("plDrone").transform; drone = Instantiate(explosion, transform.position, transform.rotation); drone.name = "drone" + i; global.enemyList.push(drone); global.enemyNames.push(drone.name); print("INDIVID ENTITY " +drone);

So, this drone has health. I fire bullets that have colliders setup so OnTriggerEnter, it depletes drone's health. When the drone reaches 0 health, I destroy the child, and splice the info from appropiate arrays. Here's code:

rigidbody.freezeRotation = true; var health:int = 10; var go:GameObject;

function Start(){ iTween.moveTo(go,{"x":-3.634033, "y":29.86236, "z":70.46572, "time":10}); iTween.rotateTo(go,{"x":270, "y":270, "z":0}); } function Update () {

//print(health); if(health<=0){ var child : GameObject = GameObject.Find(name); print(child); Destroy(child); var shootOff : GameObject = GameObject.Find("plTurrent"); var com0 = shootOff.GetComponent("SmoothLookAt_VarTarget"); com0.enabled = false;

for(i=0; i<global.enemyNames.length; i++){ if(child == global.enemyNames[i]){ global.enemyNames.splice(i, 1); global.enemyList.splice(i, 1); } }

} }

On Line 21 of last code, "if(child == global.enemyNames[i]){", I know I'm not doing something right. I think I need to convert a Transform to a GameObject. Sorry if there's something glaringly obvious. Tired and stuck. Thanx.

Comment
Add comment
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

3 Replies

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

Answer by Jessy · Apr 22, 2010 at 06:54 AM

I'll look at the code if this simple answer doesn't do it for you; I'm just going to answer the main question you're asking: You do not "convert" a Transform to a GameObject. Transform is a Component that gets attached to a GameObject. You can access the GameObject by using transform.gameObject. ".gameObject" works with any type of Component.

http://unity3d.com/support/documentation/ScriptReference/Component-gameObject.html

Comment
Add comment · Show 1 · 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
avatar image jaxx0rr · Aug 31, 2013 at 09:59 AM 0
Share

ok another question then: how to get a gameobject from transform.find ?? a: transform.Find("A").gameObject; So basically if anyone has cloned a bunch of robots and wants to select them

          if (mousePressed) {
              if (hit.collider.name == "Drone(Clone)") {
                  if (lastSelector != hit.collider.gameObject.transform.Find("DroneSelector").gameObject){
                     selectedObject = "Drone";
                     hit.collider.gameObject.transform.Find("DroneSelector").gameObject.GetComponent($$anonymous$$eshRenderer).enabled = true;
                     if (lastSelector != null) lastSelector.GetComponent($$anonymous$$eshRenderer).enabled = false;
                     lastSelector = hit.collider.gameObject.transform.Find("DroneSelector").gameObject;
                 }
              } else
 
avatar image
0

Answer by Estevominador · Sep 06, 2012 at 01:28 PM

Thanks Jessy!

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

Answer by Rickasheye · Jun 06, 2016 at 05:10 AM

easy just put the game object name then the thing .transform gameObject_Name.transform then ladada

Comment
Add comment · Show 1 · 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
avatar image tanoshimi · Jun 06, 2016 at 06:04 AM 1
Share

Yes - which is exactly what @Jessy wrote above, over six years ago...

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

transform.root.collider From Fps Tutorial issue when organized in view 1 Answer

Is transform another name for a gameObject? 2 Answers

Can't skew a gameobject transform? 2 Answers

How do I check multiple gameObjects transform positions? 3 Answers

Rotating a Vector3 in Instantiation 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