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 gavlee888 · Nov 25, 2014 at 03:41 PM · instantiateprefabcarwheelcollider

Instantiating a car prefab and adding wheel colliders to it

I am creating a car sumulation that has cars drive down a road toward a player. At the moment I have a car model prefab that I drag and drop into the scene. There is a script attached to that model that has a path and wheel collider variables, in the inspector I can drag and drop these path and collider variables onto the prefab. doing this everything works fine and the car drives down the road following the path.

What I want to do now is instanciate the prefab and attach the path and wheel collider variables to the car prefab within another "GameMaster" script, I have some code but am a bit lost, the car gets instanciated but hasn't got a path or wheel colliders attached so it doesn't move. I am a noob and would really appericate any help.

 var craClone : GameObject;
 var path : GameObject;
 carClone = Instantiate(car);
 path = GameObject.Find("Path");
 Debug.Log(path);
     
 carClone.path = path;
     
 //WheelFR = GameObject.Find("/car(Clone)/RivalCar/WheelColliders/WheelFR");

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 tw1st3d · Nov 25, 2014 at 03:42 PM 0
Share

Okay well for one, craClone should be carClone, line 1 Where is your car variable co$$anonymous$$g from? What output does path give?

avatar image gavlee888 · Nov 25, 2014 at 05:46 PM 0
Share

sorry that was a typo. I am declaring a variable carClone as a GameObject on line 1 and then on line 3 instantiating car which is a prefab of a car model containing wheel colliders and storing that in carClone. the output of the Debug.Log(path) is Path(UnityEngine.GameObject) UnityEngine.Debug:Log(Object). The path variable is created with this script

 //creating array called path
 var path : Array;
 //creating a variable rayColor and setting it equal to white
 var rayColor : Color = Color.white;
 
 //calling OnDrawGizmos function
 function OnDrawGizmos(){
     //setting Gizmos color to white
     Gizmos.color = rayColor;
     //creating an array containing all of the path child objects as transforms
     var path_objs : Array = transform.GetComponentsInChildren(Transform);
     path = new Array();
     //I DONT $$anonymous$$NOW FIND OUT
     for (var path_obj : Transform in path_objs){
         if (path_obj != transform)
             path [path.length] = path_obj;
 
     }
     //I DONT $$anonymous$$NOW FIND OUT
     for (var i: int = 0; i  < path.length; i++){
         var pos : Vector3 = path[i].position;
         if(i>0){
             var prev = path[i-1].position;
             Gizmos.DrawLine(prev,pos);
             Gizmos.DrawWireSphere(pos,0.3);
             
         }
     }
 
 }

The path variable should be used by the car as a path to follow.

Thank you for the reply and sorry if my question isn't clear.

0 Replies

· Add your reply
  • Sort: 

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

Get unity to recognize prefab in C# 2 Answers

Instantiated object rotation abruptly. 0 Answers

Instantiate prefab (button, texture) with attached script 1 Answer

instantiate problem with assigned variable 1 Answer

The variable othertransform of Prefab has not been assigned 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