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 Cherikov · Sep 02, 2013 at 06:07 AM · javascriptgameobjectinstantiate

Instantiate GameObject at Parent Transform

hey guys, just a simple one... ive attached this script to a tree, and i want it so that when clicked, the tree is destroyed and instantiated in its place is a prefab of some logs.

this is my script:

 var prefab : GameObject;
 var tree = Transform;
 
 function OnMouseDown () {
       Instantiate (prefab, tree);
     Destroy(gameObject);
 }

but it says that "No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.GameObject, System.Type, int)' was found." can you guys 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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by bubzy · Sep 02, 2013 at 06:14 AM

 using UnityEngine;
 using System.Collections;
 
 public class makeLogs : MonoBehaviour {
 
     // Use this for initialization
     public GameObject logs;
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     if(Input.GetKeyDown(KeyCode.A))
         {
         Instantiate(logs,transform.position,Quaternion.identity);
             Destroy(gameObject);
         }
         
     }
 }

this is c# but you should get the idea, the keypress is just to simulate your condition for activating the instantiation and destruction the error you are getting is because you have not correctly filled out the parameters of the instantiate command. the unity script reference site will help you with this :)

edit : this is assuming that the script is attached to the tree.

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 InfiniBuzz · Sep 02, 2013 at 06:15 AM

The instantiate function takes no transform as parameter. You can use:

 Instantiate (prefab, tree.position, tree.rotation); // or whatever position/rotation you want

or

 Instantiate (gameObject);

this makes a clone of the gameObject. (just for the record)

also the line

 var tree = Transform;


is probably not what you want. did you mean

 var tree : Transform;

? before using the tree variable you should assign it. Sorry I don't see the point of this script but I hope it helps :)

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 Panik.Studios · Dec 12, 2013 at 05:40 PM

I know this is an old as thread too but someone might have a similar question in the future so! Here is my crack at it.

 var Tree : GameObject;
 var Logs : GameObject;
 var LogSpawn : Transform; //This is an empty you attach to the tree//
 
 function Update(){
 
    if(Input.GetMouseButtonDown(0)){
 
       Destroy(Tree);
       SpawnLogs();
    }
 
 }
 
 function SpawnLogs(){
 
     Instantiate(Logs, LogSpawn.transform.position, LogSpawn.transform.rotation);
 }
 
 //You might need it to Be Logs.transform! You might also need it to say Destroy(Tree.transform) i cannot remember I use an object pool its a bit different with that//
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.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Instantiate as a child at position 2 Answers

[SOLVED] Only instantiating once 1 Answer

swap objects with instantiate 2 Answers

How to correctly convert Object to GameObject 1 Answer

Bullet 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