• 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
-1
Question by GoGamingJoe · Mar 09, 2014 at 06:36 PM · instantiatetransform

Does Anyone Know How I Would Find The Position Of A Game Object And Then Instantiate It?

 #pragma strict
 
 var spawn1 : Transform;
 var spawn2 : Transform;
 var spawn3 : Transform;
 var spawn4 : Transform;
 var blueBallSmall : Transform;
 var blueBall : Transform;
 var blueBallLarge : Transform;
 var yellowBallSmall : Transform;
 var yellowBall : Transform;
 var yellowBallLarge : Transform;
 var redBallSmall : Transform;
 var redBall : Transform;
 var redBallLarge : Transform;
 var greenBallSmall : Transform;
 var greenBall : Transform;
 var greenBallLarge : Transform;
 var pinkBallSmall : Transform;
 var pinkBall : Transform;
 var pinkBallLarge : Transform;
 var purpelBallSmall : Transform;
 var purpelBall : Transform;
 var purpelBallLarge : Transform;
 var playerObject : GameObject;
 var numberOfBunces = 0;
 var needNumber = true;
 var needSpawnPoint = true;
 var spawnPoint ;
 var numberSpawnForPoint;
 var numberBall;
 function Start () {
 if(needSpawnPoint == true){
 numberSpawnForPoint = Random.Range(1,5);    
 Debug.Log("Spawn Number " + numberSpawnForPoint);
 needSpawnPoint = false;
 }
 if(needNumber == true){
 numberBall = Random.Range(1,7);    
 Debug.Log(numberBall);
 needNumber = false;
 }
 var player : GameObject = gameObject.FindGameObjectWithTag("Player");
 }
 
 function Update () {
 var scripting : GUIBounce = playerObject.GetComponent(GUIBounce);
 numberOfBunces = scripting.noBounces;
 if (numberOfBunces == 0){
     if (numberSpawnForPoint == 1){
         spawnPoint = gameObject.Find("Spawn_Point_1").transform.position;
     }
     else if (numberSpawnForPoint == 2){
         spawnPoint = gameObject.Find("Spawn_Point_2").transform.position;
     }
         else if (numberSpawnForPoint == 3){
         spawnPoint = gameObject.Find("Spawn_Point_3").transform.position;
     }
         else{
         spawnPoint = gameObject.Find("Spawn_Point_4").transform.position;
     }
     
     if(numberSpawnForPoint == 0){
         if (numberBall == 1){
             Instantiate(blueBallSmall, Vector3(spawnPoint), Quaternion.identity);
         }
     }
 }
 }

Sorry I'm a bit of a noob but the console says that .position is not a member of gameObject but Iv'e set it to a Transform. Thanks For Any Help.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Long Fall Games · Mar 09, 2014 at 06:41 PM

two things:

  1. all those find calls are going to kill your framerate, you generally just want to do that once at the start if it can be helped.

  2. Second its GameObject.Find("object_name") not gameObject.Find when its lowercase its looking for a instance.

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 robertbu · Mar 09, 2014 at 06:45 PM

I don't see anything in your code that would generate this specific error. I do see two problems. You need to declare the type of your spawnPoint on line 29:

 var spawnPoint : Vector3;

The appropriate Instantiate() is:

  Instantiate(blueBallSmall, spawnPoint, Quaternion.identity);
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Getting instance of an sub object rather than the original's subobject 0 Answers

How to instantiate prefab over the text one letter at a time? OR how to get transform of letters in a text 0 Answers

How to Instantiate prefab as child? (Java) 1 Answer

Setting parent of instantiated object fails (Error: setting parent of prefab is disabled...) 1 Answer

Instantiate Terrain Object as child of Empty Game Object 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