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 /
This question was closed Aug 21, 2013 at 02:51 PM by DeadKenny for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DeadKenny · Aug 21, 2013 at 12:48 AM · c#gameobjectinstantiateraycasttarget

AI Instantiate targets/prefab. (pick target issue)

Ok so this time I have my AI instantiate an empty GameObject(prefab) at the hit point of one of the rays and then make that its target to follow/go towards.

The problem is that it doesn't select the prefabbed instantiated target but rather the original in he middle of the scene.

So yeah what do I need to do in order get it to pick the target which the AI insantiates.

Code:

 // This is whatever the AI targets.
 
 public Transform target;
 // This is the prefabbed target object that is instantiated.
 
 public Transform targetDummy;
 
 
 
 //and this where the magic is supposed to happen lol.
 
 if(Physics.Raycast(headdummyBone.position, fwd, out hit, maxDist, ignoreLayers)){
 
    if(startWandering == true && dummyTarget01Set == false){
 
       Instantiate(targetDummy, hit.point, transform.rotation);
 
 //this is where the target is set.
 target = targetDummy.transform;
 
 
 dummyTarget01Set = true;
 
 
 
 }
 
 
 
 
 
 }
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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by HeliosDoubleSix · Aug 21, 2013 at 01:39 AM

Set it to the result of the Instantiate ( C# code ):

 GameObject resultingInstance = (GameObject)Instantiate(targetDummy, hit.point, transform.rotation);
 target = resultingInstance.transform;
Comment
Add comment · Show 3 · 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 DeadKenny · Aug 21, 2013 at 01:32 PM 0
Share

Wait is that in Java?

Also it does not work.

no definition for transform and no extension method.

I tried adding a private Tranform instance but it didn't work.

avatar image HeliosDoubleSix · Aug 21, 2013 at 02:14 PM 0
Share

Updated answer, I forgot the casting

avatar image DeadKenny · Aug 21, 2013 at 02:39 PM 0
Share

Cool thanks bro. It worked.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

How to store player model and then swap the model to an object I Raycast hit? 0 Answers

C# GameObjects Instantiate Into Each Other Issue 1 Answer

Player instantiates Backwords 0 Answers

FPS Object-on-wall Placement 0 Answers

How to randomly spawn three non repeating gameobjects from an array? 2 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