• 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 Muzz 1 · Apr 30, 2011 at 10:30 AM · javascriptinstantiatedisplaywizard

Instantiate with a scriptable wizard

First of all, I must apologise for the sheer volume of questions I've been putting up around this topic. I must thanks everyone who's answered, and I'm considering putting up the end result for the community as a though of thank-you. Anyway, here is the question this time: I've got the ScriptableWizard working. But how does the Instantiate command work? It doesn't work for me - what do I need to do? Script:

class CityWizard extends ScriptableWizard { var building : GameObject; @MenuItem("GameObject/City!") static function City (){ ScriptableWizard.DisplayWizard("Title", CityWizard, "City", ""); } function OnWizardCreate() {

     Instantiate (building, Vector3(0,0,0) , Vector3(0,0,0));

print ("City...");

 }

}

Thank you!

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

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

Answer by Kourosh · Apr 30, 2011 at 11:52 AM

mmm... you missed some parts I guess. Try this one in C#:

using UnityEditor; using UnityEngine;

class WizardCity : ScriptableWizard { public GameObject building;

 [MenuItem ("GameObject/City")]
 static void CreateWizard () {
     ScriptableWizard.DisplayWizard<WizardCity>("City", "Create");
 }
 void OnWizardCreate () {
     Instantiate(building,Vector3.zero,Quaternion.identity);
 }  
 void OnWizardUpdate () {
     helpString = "Please assign a prefab/GameObject to instantiate";
 }   

}

The last argument of the Instantiate function is a quaternion not a vector3.

Here is the JS:

class CityWizard extends ScriptableWizard {
    var building:GameObject;
    @MenuItem ("GameObject/CityWizard")
    static function CreateWizard () {
    ScriptableWizard.DisplayWizard("City Wizard", CityWizard, "Create");
    }
    function OnWizardCreate () {
        Instantiate(building,Vector3.zero,Quaternion.identity);
    }  
    function OnWizardUpdate () {
        helpString = "Please assign a prefab/GameObject to instantiate";
    }   
}
Comment
Add comment · Show 8 · 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 Muzz 1 · Apr 30, 2011 at 12:00 PM 0
Share

$$anonymous$$ine is in Javascript, not C#.

avatar image Muzz 1 · Apr 30, 2011 at 12:25 PM 0
Share

But your last sentence was the answer! Thanks!

avatar image Kourosh · Apr 30, 2011 at 12:26 PM 0
Share

I think the problem was in you instantiate function, as I said, you used Vector3 for rotation which won't work it must be Quaternion.

avatar image Muzz 1 · Apr 30, 2011 at 02:28 PM 0
Share

Absolutely. Thanks!

avatar image Muzz 1 · Apr 30, 2011 at 02:29 PM 0
Share

Oh...just thought of something else...how would I repeat the instantiation once per frame? Would I put it in the OnWizardUpdate?

Show more comments

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How can I instantiate more prefabs as the score increases? 2 Answers

Creating a Loadout 1 Answer

Checking the distance between an instantiated object and an existing object 1 Answer

Issue With Spawning Enemies (javascript) 2 Answers

Spawn along local axis. 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges