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 Indy_z · Feb 05, 2015 at 04:29 PM · scriptingbasicsspawnpointsmap makingmap-generation

My random tree spawner isn't working

I'm trying to write a script that can spawn att random locations on a plane. the thing is, when i run my script, nothing happens.

 using UnityEngine;
 using System.Collections;
 
 public class spawnScript : MonoBehaviour {
     public GameObject Palm;
     public Vector3 spawnPos; 
 
     // Use this for initialization
     void Start () {
         spawnPos = new Vector3 (13,0,13);
         Instantiate (Palm,spawnPos,Quaternion.identity);
     }
 }

NOTE: right now the code is not writen to be in random positions, i just picked some position so i could see if it worked.

The script is a component of the prefab "palm". The other things i have in my scene is a cube(working as ground), a character controller and a point light.

Am i grouping wrong? Or am I missing something in my code?

Could someone please try to tell me what I'm doing wrong?

Comment
Add comment · Show 3
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 PrisVas · Feb 05, 2015 at 04:42 PM 0
Share

dumb question: the script is attached to something on the scene?

avatar image PrisVas · Feb 05, 2015 at 04:43 PM 0
Share

also, try this: Instantiate (Palm,spawnPos,Quaternion.identity) as GameObject;

avatar image Indy_z · Feb 06, 2015 at 01:37 PM 0
Share

Found the problem, the problem was my prefab and the spawner(and some $$anonymous$$or code errors). I created a cube and used as a spawner and that worked awesome! Thanks! I also forgot to create a prefab in the resource-folder. But after some googling and trial and error it finally worked :)

1 Reply

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

Answer by GameVortex · Feb 05, 2015 at 04:47 PM

This script is a component on the Prefab Palm, and you are trying to instantiate the prefab palm with this script? That would end badly. First of all the script as @PrisVas said needs to be in the scene, not just on a prefab in your Assets.

Second, the problem occurs then when you do have this active in the scene on the prefab you are trying to instantiate. It would instantiate the prefab, which would then create another one of this script because it is on that prefab, and then that script would instantiate another prefab which would create another one of this script and so on. It would eventually crash the program.

You need to have your spawner script on a Spawner Object, separate from the prefab you are trying to spawn. That should sort things out. I recommend you to try and follow a few more tutorials to learn the basics first, before doing a completely custom thing.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

google maps 3d API lacks detail 0 Answers

Create map of the USA 0 Answers

Adding rivers to procedural generated 2D map 1 Answer

How do I make an interactive map on Unity? 0 Answers

Can I use predifined hexagons in generating random maps? 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