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 Musclegunner · Apr 26, 2011 at 07:50 PM · javascriptinstantiaterandomclone

Instantiating a random dropped consumable item from many cloned objects

My goal is to have this script drop a random consumable item (2 or 3 objects) to drop after the 5 second time limit. I can't get each cloned object to drop a random item (or one at all for that matter). The issues I run into is either the parent object will turn into an item or no 'clones' will be instantiated and an object just spawns right on the parent. and gets a tad bit glitchy because of two objects colliding on the same world space. Please help out asap if you can! :D

#pragma strict
#pragma implicit
#pragma downcast
var prefab : Rigidbody;
var speed = 15;
var numberOfObjects = 15;
var radius = 1;
function Update()
{
    if(Input.GetButtonDown("Fire1"))
    {
        LaunchingProjectile();
    }
 }
function LaunchingProjectile()
{
    for (i = 0; i < numberOfObjects; i++)
    {
        var angle = i * Mathf.PI * 2 / numberOfObjects;
        var position = Vector3 (Mathf.Cos(angle), 0, Mathf.Sin(angle))     * radius;
        var clone : Rigidbody = Instantiate(prefab, transform.position, transform.rotation);
        clone.velocity = transform.TransformDirection( Vector3 (0, speed, 0));
        clone.transform.parent = transform;
        clone.transform.localPosition = position;
        Destroy(clone.gameObject, 5);
    }
}

Comment
Add comment · Show 1
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 HailShock1 · Jul 08, 2014 at 12:54 PM 0
Share

$$anonymous$$usclegunner...Could you please share how you got random items to drop from cloned objects when they are destroyed as I am attempting to do this and am having a bugger of time. Thank you in advance.

1 Reply

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

Answer by AngryOldMan · Apr 26, 2011 at 07:57 PM

this line

var clone : Rigidbody = Instantiate(prefab, transform.position, transform.rotation);

instead add

var offset : Vector3 = new Vector3 (1,1,1);

var clone : Rigidbody = Instantiate(prefab, transform.position + offset, transform.rotation);

then alter the offset variable so that the prefab appears in the right position

Comment
Add comment · Show 2 · 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 Musclegunner · Apr 26, 2011 at 08:17 PM 0
Share

Ok, but now how do I get a random item to drop in place of the cloned object after it's destroyed?

avatar image Musclegunner · Apr 26, 2011 at 10:00 PM 0
Share

NV$$anonymous$$ I figured out what was wrong, but thanks for the help

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

1 Person is following this question.

avatar image

Related Questions

Code only affects first clone? 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

How to instantiate 2D object at fixed location? 1 Answer

Mystery: Unexpected behavior with randoms and arrays 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