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 Msurdej · Nov 11, 2012 at 05:33 AM · c#instantiaterandomspawning

After picking up an object, spawn a new one in a random location

I'm currently working on a game that has my player picking up items that then follow the player. So far the following and picking up works, but I can't seem to make it spawn a new one.

 using UnityEngine;
 using System.Collections;
 
 public class Pickery : MonoBehaviour {
     
     public static float Counter = 0.0f;
     public GameObject parson;
     public int Timekeeper = 10;
     public GameObject cameran;
     
      void OnTriggerEnter (Collider other){
         Counter += 100f;
         Debug.Log ("Counter");
         cameran.SendMessage("Plus", Timekeeper);
         parson.transform.parent = transform;
         parson.transform.localPosition = new Vector3(0, 0, -1);
         Instantiate(parson, Vector3(Random.Range(10,-35),921,Random.Range(267,310)), Quaternion.identity);
         
     }
 }

Any help would be appreciated.

Comment
Add comment · Show 14
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 KiraSensei · Nov 11, 2012 at 12:27 PM 0
Share

What is not really working ? Do you have a compiling error ? Or nothing is instantiated ?

avatar image Msurdej · Nov 11, 2012 at 06:54 PM 0
Share

error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected

avatar image KiraSensei · Nov 11, 2012 at 07:15 PM 0
Share

Do you know the line that generates the error ? If it is the Instantiate method, maybe you should declare parson as a Transform, not a GameObject.

avatar image Msurdej · Nov 11, 2012 at 07:21 PM 0
Share

Doing that seems to get me this error, on both the line of code that declares parson and the one that instantiates a new one:

Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.

avatar image KiraSensei · Nov 11, 2012 at 07:29 PM 0
Share

Did you try :

public Transform parson;

Show more comments

1 Reply

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

Answer by Msurdej · Nov 11, 2012 at 09:37 PM

Question was answered needed to put

`parson = Instantiate(parson, new Vector3(Random.Range(10,-35),921,Random.Range(267,310)), Quaternion.identity)as GameObject;`

as the code instead of what I had. Thank you Kmulla and KiraSensei for your help.

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

11 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

Related Questions

AI spawning areas. What are the ways to make them? 1 Answer

Spawning prefabs dependant upon Health UI? 2 Answers

Trouble with Instantiation of objects 2 Answers

Instantiating at different rates 1 Answer

How do I spawn objects randomly near an object then delete them? 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